简体   繁体   English

为什么我在使用 Pillow 将图像保存在 python 中时出现错误?

[英]Why i'm getting an error while saving images in python using Pillow?

hi everyone I'm trying to save images in python, using PIL, but when I run my gui application and when I save them an error occurs, the images are saved but not like an image.大家好,我正在尝试使用 PIL 将图像保存在 python 中,但是当我运行我的 gui 应用程序并保存它们时发生错误,图像被保存但不像图像。 When I open them, they look like a text file...当我打开它们时,它们看起来像一个文本文件......

This is the code I'm using:这是我正在使用的代码:

def save_all(images):                                        
    count = 1                                                
    for i in images:                                         
        i.save("image" + str(count) + ".png", format="png")  
        count += 1

I suspect it's because the format is wrong - try:我怀疑这是因为格式错误 - 尝试:

def save_all(images):                                        
    count = 1                                                
    for i in images:                                         
        i.save(f"image{count}.{i.format}", format=i.format)  
        count += 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 python 中写入文本文件时出现错误? - Why I'm getting error while writing into text file in python? 使用pip安装枕头时出现错误 - Getting Error While Installing Pillow using pip 在 AWS Lambda 上的 python 中使用枕头 package 保存图像时出现错误/错误的内容类型 - Error/Wrong Content-Type while saving image using pillow package in python on AWS Lambda 使用Python使用Pillow调整图像大小时,为什么颜色会改变? - Using Python to resize images using Pillow, why are the colours changing? 使用枕头Python调整图像大小 - Resizing Images using Pillow Python 为什么在 python 中打印今天的日期时会出现这样的错误? - Why I'm getting error like this while printing today's date in python? 为什么在 python 中打印本地日期时间时出现错误 - Why i'm getting error while printing local date time in python 使用PyInstaller时出现以下错误:OSError:[Errno 2]没有这样的文件或目录。 我正在使用Ubuntu 15.04和Python 2.7 - I'm getting the following error while using PyInstaller: OSError: [Errno 2] No such file or directory. I'm using Ubuntu 15.04 and Python 2.7 为什么我在保存文件时收到 Errno 13 错误? - Why am I getting Errno 13 Error while saving the file? 为什么在构建 docker 图像时出现此错误? - Why I'm getting this error while building docker image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM