本站改版新增arduino频道
pillow库将图片转为buf
单色屏可用,特别是oled和墨水屏
#this is a tools to conver image to buf
#20220604 by jd3096
from PIL import Image
def getbuffer(filename):
image = Image.open(filename)
image=image.convert("1")
buf = []
headname=filename.split('.')[0]
imwidth, imheight = image.size
pixels = image.load()
j=0
bitvalue=0
for y in range(imheight):
for x in range(imwidth):
if pixels[x, y] == 255:
bitvalue=bitvalue+pow(2,j)
j+=1
if j==8:
buf.append(bitvalue)
j=0
bitvalue=0
fbval='fbval_'+headname+'='+str(buf)
fbtext='fb_'+headname+'=framebuf.FrameBuffer(bytearray('+'fbval_'+headname+'),'+str(imwidth)+','+str(imheight)+',framebuf.MONO_HLSB)'
result=fbval+'\n'+fbtext
return result
a=getbuffer('1.jpg')
print(a)来源:https://blog.csdn.net/jd3096/article/details/125132928
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.009425163269043 seconds