MicroPython动手做(16)——掌控板之图片图像显示
掌控板板载1.3英寸OLED显示屏,分辨率128x64。显示图像有两种方法,一是 bmp格式的图片,可以用取模软件转换为16进制图像数据,在OLED屏显示图像。二是pbm格式的图片,在OLED屏显示图像。板内内置图片为pbm格式,相对于16进制图像数据,pbm格式占用内存更少,可以使掌控板储存更多的图片,我们也可以将自己制作的图片,转换为pbm或者bmp格式显示在掌控板上。1、OLED屏显示心在跳动
#MicroPython动手做(16)——掌控板之图片图像显示
#OLED屏显示内置图像心在跳动
from mpython import *
import time
image_picture = Image()
while True:
oled.fill(0)
oled.blit(image_picture.load('face/2.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/1.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
8、A、B键控制图片转换显示
#MicroPython动手做(16)——掌控板之图片图像显示
#A、B键控制图片转换显示
from mpython import *
import music
def callback_button_a_pressed():
oled.fill(0)
bmp_wZZv = bytearray()
oled.Bitmap(0, 0, bmp_wZZv, 128, 64, 1)
oled.show()
def callback_button_b_pressed():
oled.fill(0)
bmp_h61P = bytearray()
oled.Bitmap(0, 0, bmp_h61P, 128, 64, 1)
oled.show()
def on_button_a_pressed():
while True:
if button_a.value() == 0:
yield callback_button_a_pressed()
else:
yield
def on_button_b_pressed():
while True:
if button_b.value() == 0:
yield callback_button_b_pressed()
else:
yield
func_button_a_pressed = on_button_a_pressed()
func_button_b_pressed = on_button_b_pressed()
while True:
next(func_button_a_pressed)
next(func_button_b_pressed)
#MicroPython动手做(16)——掌控板之图片图像显示
#OLED显示外部图片
from mpython import *
import time
while True:
oled.fill(0)
oled.Bitmap(0, 0, bytearray(), 128, 64, 1)
oled.show()
time.sleep(1)
oled.fill(0)
oled.Bitmap(0, 0, bytearray(), 128, 64, 1)
oled.show()
time.sleep(1)
#MicroPython动手做(16)——掌控板之图片图像显示
#二只小象
from mpython import *
while True:
oled.fill(0)
oled.Bitmap(0, 0, bytearray(), 128, 64, 1)
oled.show()
mPython 图形编程
<b>2、流动的时间</b>
#MicroPython动手做(16)——掌控板之图片图像显示
#流动的时间
from mpython import *
import time
image_picture = Image()
while True:
oled.fill(0)
oled.blit(image_picture.load('face/Progress/Timer 0.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/Progress/Timer 1.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/Progress/Timer 2.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/Progress/Timer 3.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/Progress/Timer 4.pbm', 0), 32, 0)
oled.show()
mPython 图形编程
3、变幻的人脸
#MicroPython动手做(16)——掌控板之图片图像显示
#变幻的人脸
from mpython import *
import time
image_picture = Image()
while True:
oled.fill(0)
oled.blit(image_picture.load('face/8.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/9.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/12.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/3.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
oled.fill(0)
oled.blit(image_picture.load('face/4.pbm', 0), 32, 0)
oled.show()
time.sleep(1)
mPython 图形编程
4、OLED显示外部图片
OLED屏幕只能显示颜色深度为1或者就是黑白模式的bmp格式,可以使用Photoshop、“画图”或者其他图片显示软件进行转换。转换好格式的图片需要使用取模工具对图片进行取模,转换的图片大小应该为128*64,也就是掌控板屏幕的大小。所选的图片线条要分明,且颜色不能太过丰富。
(1)选择一张图片
(2)用在线PS打开图片,这里使用 https://www.uupoop.com/
(3)调整为128*64规格,另存为bmp格式
(4)安装小图片取模工具Image2Lcd
下载地址:
http://7dx.0098118.com/wwb5/image2lcd32.zip
(5)去头去尾要中间(取模数据)
(6)将复制的16进制图像数据粘贴在下列指令的空格处。
描述:OLED绘制16进制数组图像。将16进制数据转换成图像显示在oled屏幕的指定位置处。尝试将程序搭建好,将图片显示出来。
mPython 图形编程
5、尝试转换显示一张网络图片
在线转换为bmp格式
小图片取模工具Image2Lcd来取模(通过调整亮度选取合适图案)
页:
[1]
2