python 將windows字體中的漢字生成圖片的方法


#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"))


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM