📜  Python PIL | Image.show() 方法

📅  最后修改于: 2022-05-13 01:55:25.587000             🧑  作者: Mango

Python PIL | Image.show() 方法

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 Image 模块提供了一个同名的类,用于表示 PIL 图像。该模块还提供了许多工厂函数,包括从文件加载图像和创建新图像的函数。
Image.show()显示此图像。此方法主要用于调试目的。
在 Unix 平台上,此方法将图像保存到临时 PPM 文件中,并调用 xv 实用程序。在 Windows 上,它将图像保存到临时 BMP 文件中,并使用标准 BMP 显示实用程序来显示它(通常是 Paint)。

使用的图像:

Python3
# importing Image class from PIL package
from PIL import Image
 
# creating a object
im = Image.open(r"C:\Users\System-Pc\Desktop\home.png")
 
im.show()


Python3
# importing Image class from PIL package
from PIL import Image
 
# creating a object
im = Image.open(r"C:\Users\System-Pc\Desktop\tree.jpg")
 
im.show()


输出:

另一个例子:使用 .jpg 扩展名使用 show() 打开图像。
使用的图像:

Python3

# importing Image class from PIL package
from PIL import Image
 
# creating a object
im = Image.open(r"C:\Users\System-Pc\Desktop\tree.jpg")
 
im.show()

输出: