OLED显示图像尺寸调整困难

2024-04-29 11:23:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在调整图像大小以显示在OLED设备上。在

我要显示的图像是: enter image description here

目前,我的OLED显示器只显示图像的一小部分: enter image description here

基于How to resize image?,我在脚本中添加了new_img = img.resize((128,128)),以调整图像的大小。但是,屏幕上显示的却是图像的相同部分。当我试图为resize参数(64x64)输入较低的图像大小时,终端打印:

pi@raspberrypi:~/project $ python colors.py --display ssd1351 --width 128 --height 128 --interface spi --spi-bus-speed 16000000 --gpio-data-command 20
Version: luma.oled 2.3.1 (luma.core 1.3.0)
Display: ssd1351
Interface: spi
Dimensions: 128 x 128
------------------------------------------------------------
Traceback (most recent call last):
  File "colors.py", line 87, in <module>
    main()
  File "colors.py", line 30, in main
    device.display(new_img)
  File "/usr/local/lib/python2.7/dist-packages/luma/oled/device.py", line 371, in display
    assert(image.size == self.size)
AssertionError

有什么想法我可以调整图像的大小,为OLED显示器?在

我的完整脚本是:

^{pr2}$

Tags: inpy图像imagespi脚本imgluma
1条回答
网友
1楼 · 发布于 2024-04-29 11:23:48

好吧,我解决了这个问题:

img = Image.open(img_path)  
img = img.resize((128, 128), Image.ANTIALIAS) \
    .transform(device.size, Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
    .convert(device.mode)

所以在运行transform和convert之前,先调整图像大小。在

相关问题 更多 >