如何在python中输出图片信息
时间: 2024-05-07 15:16:21 浏览: 89
你可以使用Pillow库,先将图片读取为Image对象,然后调用Image对象的属性和方法来获取图片信息,例如:
```python
from PIL import Image
# 读取图片
img = Image.open('image.jpg')
# 获取图片大小
width, height = img.size
print('图片大小:{}x{}'.format(width, height))
# 获取图片格式
print('图片格式:{}'.format(img.format))
# 获取图片模式
print('图片模式:{}'.format(img.mode))
# 获取图片颜色通道
if img.mode == 'RGB':
print('颜色通道:RGB')
elif img.mode == 'RGBA':
print('颜色通道:RGBA')
elif img.mode == 'L':
print('颜色通道:灰度图')
# 获取图片像素值
pixel_values = list(img.getdata())
print('像素值:{}'.format(pixel_values))
```
注意:以上代码仅供参考,具体操作需要根据不同的图片格式和需求进行调整。
阅读全文
相关推荐

















