用python生成多个图片组成的二进制图片,并逐一在micro python的st7789驱动的屏幕上显示,代码示例
时间: 2023-04-08 13:02:55 浏览: 204
以下是Python代码示例:
```python
from PIL import Image
import io
import os
# 生成多个图片
img1 = Image.open("image1.jpg")
img2 = Image.open("image2.jpg")
img3 = Image.open("image3.jpg")
# 将多个图片保存为二进制格式
img1_bytes = io.BytesIO()
img1.save(img1_bytes, format='JPEG')
img1_bytes = img1_bytes.getvalue()
img2_bytes = io.BytesIO()
img2.save(img2_bytes, format='JPEG')
img2_bytes = img2_bytes.getvalue()
img3_bytes = io.BytesIO()
img3.save(img3_bytes, format='JPEG')
img3_bytes = img3_bytes.getvalue()
# 将多个二进制图片组合成一个二进制图片
all_images_bytes = img1_bytes + img2_bytes + img3_bytes
# 将二进制图片逐一显示在屏幕上
import st7789
import machine
spi = machine.SPI(1, baudrate=40000000, polarity=1, phase=1, sck=machine.Pin(18), mosi=machine.Pin(19))
display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(23, machine.Pin.OUT), cs=machine.Pin(5, machine.Pin.OUT), dc=machine.Pin(16, machine.Pin.OUT))
# 设置屏幕显示方向
display.init()
display.rotation(3)
# 显示第一张图片
img1 = Image.open(io.BytesIO(all_images_bytes[:len(img1_bytes)]))
display.image(img1, 0, 0)
# 显示第二张图片
img2 = Image.open(io.BytesIO(all_images_bytes[len(img1_bytes):len(img1_bytes)+len(img2_bytes)]))
display.image(img2, 0, 0)
# 显示第三张图片
img3 = Image.open(io.BytesIO(all_images_bytes[len(img1_bytes)+len(img2_bytes):]))
display.image(img3, 0, 0)
```
注意:以上代码示例仅供参考,具体实现方式可能因硬件设备和软件版本而异。
阅读全文