首页 > 解决方案 > PIL Image拒绝保存文件

问题描述

我正在尝试使用 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

无论出于何种原因,它都拒绝保存图像,任何帮助将不胜感激!

谢谢!

标签: python-3.xpycharmpython-imaging-library

解决方案


线

image_debug.save = ('converted_image.png')

应该

image_debug.save('converted_image.png')

推荐阅读