pygame将文字保存为图片形式

时间:2023-03-10 06:42:16
pygame将文字保存为图片形式
近期自学了点小基础,分享一下用pygame制作字体图片的方法:
# 将文字保存为图片形式
import pygame
import sys
pygame.init()
导入字体包,也可以调用系统字体pygame.font.SysFont()
# 查找所有系统内置字体
pygame.font.get_fonts()
# 设置系统可识别的字体
myfont=pygame.font.SysFont('华文彩云',60)
font1=pygame.font.Font('./font/meng.ttf',60)
text='Come不瘦Er十斤/nLxL不换头像On!'
text1='Li@某人'
fontImg1=font1.render(text,True,(25,117,223))
fontImg2=font1.render(text1,True,(222,6,168))
# A=font1.blit([fontImg1,[100,100],fontImg2,[200,200]])
# pygame.image.save(a,'./img/fontImg4.png')
将字体图片保存的位置
pygame.image.save(fontImg1,'./img/fontImgL123.png')