如何使用 Python 读取图像文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3735553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 12:29:31  来源:igfitidea点击:

How do I read an image file using Python?

pythonimagefile

提问by Nimmy

How do I read an image file and decode it using Python?

如何读取图像文件并使用 Python 对其进行解码?

回答by TheGentleOne

The word "read" is vague, but here is an example which reads a jpeg file using the Image class, and prints information about it.

“读取”一词含糊不清,但这里有一个示例,它使用 Image 类读取 jpeg 文件,并打印有关它的信息。

from PIL import Image
jpgfile = Image.open("picture.jpg")

print(jpgfile.bits, jpgfile.size, jpgfile.format)