Posted in Python onAugust 22, 2019
今天在用python3+ImageFont输出中文时,结果显示乱码
# coding:utf-8 from PIL import Image, ImageDraw, ImageFont image= Image.new('RGB', (559, 320),(255,255,255)) draw = ImageDraw.Draw(image) # draw.text() font = ImageFont.truetype("arial", 40, encoding="unic") # 设置字体 draw.text((100, 50), "哈哈哈", 'black', font) # del draw image.show() # printers = win32print.EnumPrinters(10) # print printers
有个简单的解决方法,修改字体为simsun.ttc即可:
# coding:utf-8 from PIL import Image, ImageDraw, ImageFont image= Image.new('RGB', (559, 320),(255,255,255)) draw = ImageDraw.Draw(image) # draw.text() font = ImageFont.truetype("simsun.ttc", 40, encoding="unic") # 设置字体 draw.text((100, 50), "哈哈哈", 'black', font) # del draw image.show() # printers = win32print.EnumPrinters(10) # print printers
以上这篇解决Python3用PIL的ImageFont输出中文乱码的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。
解决Python3用PIL的ImageFont输出中文乱码的问题
- Author -
小啊小木头声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@