Python OLED显示器图像尺寸调整困难

Python OLED显示器图像尺寸调整困难,python,image,resize,image-resizing,Python,Image,Resize,Image Resizing,我正在尝试调整图像大小以在OLED设备上显示 我要显示的图像是: 目前,我的OLED显示屏仅显示图像的一小部分: 基于,我在脚本中添加了new\u img=img.resize((128128))来调整图像的大小。但是,屏幕上会显示相同部分的图像。当我尝试为resize参数(64x64)输入较低的图像大小时,terminal打印: pi@raspberrypi:~/project $ python colors.py --display ssd1351 --width 128 --heigh

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

我要显示的图像是:

目前,我的OLED显示屏仅显示图像的一小部分:

基于,我在脚本中添加了
new\u img=img.resize((128128))
来调整图像的大小。但是,屏幕上会显示相同部分的图像。当我尝试为resize参数(64x64)输入较低的图像大小时,terminal打印:

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

好的,我通过以下方法解决了这个问题:

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之前,请先调整图像大小。

我看到图片和图形,我向上投票……您可以在底部执行
device=get\u device()
,然后尝试在
main()
中使用它。为什么那句话不在主语里?尽可能避免全局性。@贝利:我根据OLED Luma库repo上的演示脚本修改了脚本。我认为这是因为在原始脚本中还有其他函数,我现在已经删除了这些函数。感谢您指出这一点,我稍后可能会谈到这一部分。您的设备显示为128x128,因此将其大小调整为500x500可能不正确…@Mark。谢谢你指出这一点。我现在将其大小调整为128x128。我不再得到错误,但只显示原始图像的相同部分。我试着降低,但是断言错误返回。你根本不需要转换
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)