Python - 如何将列表保存为图像? [英] Python - How to save a list as an image?

查看:195
本文介绍了Python - 如何将列表保存为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成了一个常规列表.是否可以将此列表保存为 JPEG 图像或 PNG 或其他格式,以便我可以打开图像并查看它?我目前正在尝试使用 python 成像库 (PIL) 来解决这个问题.

I generate a regular list. Is it possible to save this list as a JPEG image or PNG or whatever so that I can open the image and look at it? I am currently trying to figure it out using the python imaging library (PIL).

推荐答案

以下是可能的解决方案之一:

Here is one of the possible solutions:

  1. 使用以下方法创建一个空图像对象:Image.new(mode, size, color)

  1. Create an empty image object using: Image.new(mode, size, color)

修改图像对象以包含列表"中的数据

Modify the image object to contain the data from the "list"

保存图片

例如:

new_img = Image.new("L", (NEW_X_SIZE, NEW_Y_SIZE), "white")
new_img.putdata(new_img_list)
new_img.save('out.tif')

这篇关于Python - 如何将列表保存为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆