在Python中,如何从一些源数据轻松生成图像文件?

时间:2022-02-18 06:52:43

I have some some data that I would like to visualize. Each byte of the source data roughly corresponds to a pixel value of the image.

我有一些我想要想象的数据。源数据的每个字节大致对应于图像的像素值。

What is the easiest way to generate an image file (bitmap?) using Python?

使用Python生成图像文件(位图?)的最简单方法是什么?

2 个解决方案

#1


You can create images with a list of pixel values using Pillow:

您可以使用Pillow创建包含像素值列表的图像:

from PIL import Image

img = Image.new('RGB', (width, height))
img.putdata(my_list)
img.save('image.png')

#2


Have a look at PIL and pyGame. Both of them allow you to draw on a canvas and then save it to a file.

看看PIL和pyGame。它们都允许您在画布上绘制然后将其保存到文件中。

#1


You can create images with a list of pixel values using Pillow:

您可以使用Pillow创建包含像素值列表的图像:

from PIL import Image

img = Image.new('RGB', (width, height))
img.putdata(my_list)
img.save('image.png')

#2


Have a look at PIL and pyGame. Both of them allow you to draw on a canvas and then save it to a file.

看看PIL和pyGame。它们都允许您在画布上绘制然后将其保存到文件中。