繁体   English   中英

如何生成确定 python 中每个像素颜色的图像?

[英]How can i generate an image determining the color of each pixel in python?

我需要一种生成图像的方法,以便我可以通过数组来决定每个像素的宽度、长度和颜色。 我怎么能在 Python 中做到这一点?

这是一种使用 Pillow 和数组的方法

from PIL import Image

# Your image as a 3d-array using RGB color values for each pixel
imageArray = [[(0, 0, 0), (0, 0, 0), (0, 0, 0)],
              [(0, 0, 0), (0, 0, 0), (0, 0, 0)],
              [(0, 0, 0), (0, 0, 0), (0, 0, 0)]]

# Generate image
img = Image.new("RGB", (len(imageArray[0]), len(imageArray)), "#ffffff")

for i, row in enumerate(imageArray):
    for j, pixel in enumerate(row):
        img.putpixel((j, i), pixel)

img.save("output.png")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM