我正在尝试使用Pillow的图像模块编写一个简单的脚本,以将图像从RGBA转换为RGB,这是一个非常简单的任务。但是,图像无法安全保存,这是怎么回事?
这是整个.py文件。 (.py和src_images文件夹都在同一目录中。)
from PIL import Image
image_debug = Image.open('src_images/image1.png')
image_debug = image_debug.convert('RGB')
image_debug.save = ('converted_image.png')
image_debug = Image.open('converted_image.png')
运行时,出现以下错误:
Traceback (most recent call last):
File "/home/armin/PycharmProjects/dynamic-wal-changer/tests/DEBUG.py", line 7, in <module>
image_debug = Image.open('converted_image.png')
File "/home/armin/PycharmProjects/dynamic-wal-changer/venv/lib/python3.7/site-packages/PIL/Image.py", line 2580, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'converted_image.png'
Process finished with exit code 1
无论出于何种原因,它都拒绝保存图像,我们将不胜感激!
谢谢!
答案 0 :(得分:0)
线
image_debug.save = ('converted_image.png')
应该是
image_debug.save('converted_image.png')