6
6
"""
7
7
import os
8
8
import pygame
9
+
9
10
chinese_dir = 'chinese'
10
11
if not os .path .exists (chinese_dir ):
11
12
os .mkdir (chinese_dir )
12
13
13
14
pygame .init ()
14
- start , end = (0x4E00 , 0x9FA5 )#汉字编码范围
15
- for codepoint in range (int (start ), int (end )):
16
- word = chr (codepoint )
17
- font = pygame .font .Font ("MSYH.TTC" , 22 )#当前目录下要有微软雅黑的字体文件msyh.ttc,或者去c:\Windows\Fonts目录下找
18
- rtext = font .render (word , True , (0 , 0 , 0 ), (255 , 255 , 255 ))
19
- pygame .image .save (rtext , os .path .join (chinese_dir ,word + ".png" ))
15
+
16
+ # 1. 写出所有的汉字
17
+ # start, end = (0x4E00, 0x9FA5) # 汉字编码范围
18
+ #
19
+ # for codepoint in range(int(start), int(end)):
20
+ # word = chr(codepoint)
21
+ # font = pygame.font.Font("MSYH.TTC", 22) # 当前目录下要有微软雅黑的字体文件msyh.ttc,或者去c:\Windows\Fonts目录下找
22
+ # rtext = font.render(word, True, (0, 0, 0), (255, 255, 255))
23
+ # pygame.image.save(rtext, os.path.join(chinese_dir, word + ".png"))
24
+
25
+ # 2. 指定汉字 对于不同的字体 可以切换MSYH.TTC文件就行
26
+ word = '新'
27
+ font = pygame .font .Font ("MSYH.TTC" , 22 ) # 当前目录下要有微软雅黑的字体文件msyh.ttc,或者去c:\Windows\Fonts目录下找
28
+ rtext = font .render (word , True , (0 , 0 , 0 ), (255 , 255 , 255 ))
29
+ pygame .image .save (rtext , os .path .join (chinese_dir , word + ".png" ))
30
+
0 commit comments