python如何显示图片
时间: 2024-08-30 10:03:30 浏览: 135
在Python中,你可以使用多种库来显示图片,其中最常用的是`PIL`(Python Imaging Library),现在它已整合进标准库并称为`Pillow`。以下是使用`Pillow`库展示图片的基本步骤:
```python
from PIL import Image
# 打开图片文件
img = Image.open('image_path.jpg') # 替换 'image_path.jpg' 为你图片的实际路径
# 显示图片
img.show()
# 或者如果你想保存到屏幕截图,可以使用以下代码(仅支持Windows系统)
import io
from PIL import ImageGrab
ImageGrab.grab().save('screenshot.png')
```
如果你想要更复杂的图像处理操作,比如调整大小、裁剪等,`PIL`也提供了丰富的功能。
阅读全文
相关推荐















