怎么保存图片python
时间: 2024-03-12 11:40:35 浏览: 148
以下是两种保存图片的方法:
1. 使用matplotlib保存图片:
```python
import matplotlib.pyplot as plt
from PIL import Image
# 打开图片
image = Image.open('image.jpg')
# 显示图片
plt.imshow(image)
plt.show()
# 保存图片
plt.savefig('image.png')
```
2. 使用numpy和rasterio保存图片:
```python
import numpy as np
import rasterio
# 读取图片
img = rasterio.open('image.tif').read()
# 保存图片
rasterio.open('new_image.tif', 'w', driver='GTiff', height=img.shape[1], width=img.shape[2], count=img.shape[0], dtype=img.dtype).write(img)
```
阅读全文
相关推荐












