[英]I am trying to save this image in a folder but it is showing this error. What am I doing wrong here?
这是我的代码
from PIL import Image
from PIL import ImageDraw
# Open an Image
FRAME_SIZE = (720,1280)
img = Image.new('RGB', FRAME_SIZE, color = 'black')
# Call draw Method to add 2D graphics in an image
I1 = ImageDraw.Draw(img)
# Add Text to an image
I1.text((100, 100), "nice Car", fill=(255, 32, 0))
# Display edited image
img.show()
# Save the edited image
img.save("./new_folder/car2.png")
这是错误。
Traceback (most recent call last):
File "D:\Python Projects\devops-directive-hello-world\trial.py", line 19, in <module>
img.save("./new_folder/car2.png")
File "C:\Users\Pushpendra\Desktop\Drone\devops-directive-hello-world\lib\site-packages\PIL\Image.py", line 2317, in save
fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: './new_folder/car2.png'
进程以退出代码 1 结束
只需更改目标文件夹。
img.save("car2.png")
这会成功的。 至少你必须选择一个现有的目录
发生此错误的最可能原因是您的 Python 目录位于 C 中:因此您的相对路径仅引用您的 Python 目录。
在这种情况下,解决方法可以是使用绝对路径,如下所示:'D/Python Projects/newfolder/'
希望它能解决你的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.