#encoding: utf-8
import os
import pygame
chinese_dir = '黑體常規'
if not os.path.exists(chinese_dir):
os.mkdir(chinese_dir)
pygame.init()
start,end = (0x4E00, 0x9FA5) # 漢字編碼范圍
for codepoint in range(int(start), int(end)):
word = chr(codepoint)
font = pygame.font.Font("simhei.ttf", 64)
# 當前目錄下要有微軟雅黑的字體文件msyh.ttc,或者去c:\Windows\Fonts目錄下找
# 64是生成漢字的字體大小
rtext = font.render(word, True, (0, 0, 0), (255, 255, 255))
pygame.image.save(rtext, os.path.join(chinese_dir, word + ".png"))