📅  最后修改于: 2022-03-11 14:56:40.831000             🧑  作者: Mango
from PIL import Image, ImageDraw, ImageFont
import numpy as np
w_disp = 128
h_disp = 64
fontsize = 32
text = u"ä½ å¥½!"
imageRGB = Image.new('RGB', (w_disp, h_disp))
draw = ImageDraw.Draw(imageRGB)
font = ImageFont.truetype("/Library/Fonts/Arial Unicode.ttf", fontsize)
w, h = draw.textsize(text, font=font)
draw.text(((w_disp - w)/2, (h_disp - h)/2), text, font=font)
image8bit = imageRGB.convert("L")
imageRGB.save("NiHao! RGB.bmp")
image8bit.save("NiHao! 8bit.bmp")
imagenice_80 = image8bit.point(lambda x: 0 if x < 80 else 1, mode='1')
imagenice_128 = image8bit.point(lambda x: 0 if x < 128 else 1, mode='1')
imagenice_80.save("NiHao! nice 1bit 80.bmp")
imagenice_128.save("NiHao! nice 1bit 128.bmp")