← 返回首页
状态:已完成

【Python 代码】将内存中的图像数据写入指定路径的文件(使用合适的库如PIL或matplotlib)

from PIL import Image import numpy as np # 假设 image_data 是内存中的图像数组,output_path 是目标路径 # 若 image_data 为 numpy 数组(H, W, C)或(H, W) img = Image.fromarray(image_data.astype('uint8')) img.save(output_path)