python-3.x - 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
无论出于何种原因,它都拒绝保存图像,任何帮助将不胜感激!
谢谢!
解决方案
线
image_debug.save = ('converted_image.png')
应该
image_debug.save('converted_image.png')
推荐阅读
- node.js - Firebase 电子邮件功能找不到用户
- mongodb - RESTful API、补丁、猫鼬更新命令不更新,而只是清除字段
- java - Spring Security:WebSecurityConfig 类 `antMatchers(...).permitAll()` 不起作用
- pine-script - 在 TradingView 中加载和加载字符串
- python-3.x - 当 AutomationFocusChangedEventHandler 在前台运行应用程序窗口时,如何阻止我的 Windows python 3 应用程序崩溃?
- javascript - 带有角度组件问题的引导下拉菜单
- c# - HBase 自定义地图归约器作业
- mysql - MySQL 触发器 - 复制新的。插入的数据与现有的列值进行比较,如果它们匹配,则将它们插入到其他表中
- python - 散景:根据通过 DateSlider 过滤的日期更新地图
- c# - 验证表单上的整数字段