驴友花雕 发表于 2020-4-22 09:39:55

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)

驴友花雕 发表于 2020-4-24 09:21:34

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)

驴友花雕 发表于 2020-4-23 17:24:36

#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)

驴友花雕 发表于 2020-4-23 18:52:11

#MicroPython动手做(16)——掌控板之图片图像显示
#二只小象

from mpython import *
while True:
    oled.fill(0)
    oled.Bitmap(0, 0, bytearray(), 128, 64, 1)
    oled.show()

驴友花雕 发表于 2020-4-22 09:44:00

mPython 图形编程


驴友花雕 发表于 2020-4-22 09:47:32


驴友花雕 发表于 2020-4-23 10:45:29

<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()

驴友花雕 发表于 2020-4-23 10:50:28

mPython 图形编程




驴友花雕 发表于 2020-4-23 11:03:41


驴友花雕 发表于 2020-4-23 11:06:53

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)

驴友花雕 发表于 2020-4-23 11:18:24

mPython 图形编程

驴友花雕 发表于 2020-4-23 11:23:46


驴友花雕 发表于 2020-4-23 15:29:16

4、OLED显示外部图片
OLED屏幕只能显示颜色深度为1或者就是黑白模式的bmp格式,可以使用Photoshop、“画图”或者其他图片显示软件进行转换。转换好格式的图片需要使用取模工具对图片进行取模,转换的图片大小应该为128*64,也就是掌控板屏幕的大小。所选的图片线条要分明,且颜色不能太过丰富。
(1)选择一张图片



驴友花雕 发表于 2020-4-23 15:32:27

(2)用在线PS打开图片,这里使用 https://www.uupoop.com/


驴友花雕 发表于 2020-4-23 15:37:09

(3)调整为128*64规格,另存为bmp格式


驴友花雕 发表于 2020-4-23 16:55:28

(4)安装小图片取模工具Image2Lcd
下载地址:
http://7dx.0098118.com/wwb5/image2lcd32.zip



驴友花雕 发表于 2020-4-23 17:15:32

(5)去头去尾要中间(取模数据)


驴友花雕 发表于 2020-4-23 17:21:15

(6)将复制的16进制图像数据粘贴在下列指令的空格处。

描述:OLED绘制16进制数组图像。将16进制数据转换成图像显示在oled屏幕的指定位置处。尝试将程序搭建好,将图片显示出来。

mPython 图形编程


驴友花雕 发表于 2020-4-23 17:50:27


驴友花雕 发表于 2020-4-23 18:39:38

5、尝试转换显示一张网络图片


驴友花雕 发表于 2020-4-23 18:43:12

在线转换为bmp格式


驴友花雕 发表于 2020-4-23 18:48:38

小图片取模工具Image2Lcd来取模(通过调整亮度选取合适图案)



页: [1] 2
查看完整版本: MicroPython动手做(16)——掌控板之图片图像显示