this nice answer의 스크립트로 시작했습니다. "RGB"에 대해서는 문제없이 작동하지만 8 비트 그레이 스케일 "L"및 1 비트 흑백/"1"PIL 이미지 모드는 검은 색으로 보입니다. 내가 도대체 뭘 잘못하고있는 겁니까?PIL을 사용하여 다국어 텍스트 그리기 및 1 비트 및 8 비트 비트 맵으로 저장
from PIL import Image, ImageDraw, ImageFont
import numpy as np
w_disp = 128
h_disp = 64
fontsize = 32
text = u"你好!"
for imtype in "1", "L", "RGB":
image = Image.new(imtype, (w_disp, h_disp))
draw = ImageDraw.Draw(image)
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)
image.save("NiHao! 2 " + imtype + ".bmp")
data = np.array(list(image.getdata()))
print data.shape, data.dtype, "min=", data.min(), "max=", data.max()
출력 :
(8192,) int64 min= 0 max= 0
(8192,) int64 min= 0 max= 0
(8192, 3) int64 min= 0 max= 255