python读取图片的代码
时间: 2023-10-12 11:13:32 浏览: 41
可以使用Python的Pillow库来读取图片。以下是一个示例代码,演示如何读取一张图片并显示出来:
```python
from PIL import Image
# 读取图片
img = Image.open('image.jpg')
# 显示图片
img.show()
```
在上面的代码中,`Image.open()`方法用于打开图片文件,`show()`方法用于显示图片。你需要将`image.jpg`替换为你自己的图片文件名或者路径。
相关问题
python读取图片代码
你可以使用Python中的Pillow库来读取图片。以下是一个简单的示例代码:
```python
from PIL import Image
# 打开图片
image = Image.open('path/to/image.jpg')
# 显示图片
image.show()
# 获取图片大小
width, height = image.size
# 获取像素值
pixels = image.load()
# 获取指定像素的RGB值
r, g, b = pixels[x, y]
```
请注意,`path/to/image.jpg`应该替换为你的图片文件路径。
Python读取图片代码
这里有一个简单的示例代码,可以帮助你读取和显示图片:
from PIL import Image
# 打开图片
img = Image.open('image.jpg')
# 显示图片
img.show()