繁体   English   中英

如何设置单个像素的颜色

[英]How to set an individual pixel's color

我试图遍历图像的每个像素,处理该像素,并将像素设置为新颜色。

我尝试过使用Pillow:

from PIL import Image
picture = Image.open("image.png")

# Get the size of the image
width, height = picture.size

# Process every pixel
for x in range(0, width):
    for y in range(0, height):
        current_color = picture.getpixel( (x,y) )
        print(current_color)
        new_color = processPixel(current_color)
        picture.putpixel( (x,y), new_color)

但是打印current_color只会为图像中的每个像素打印0

是我正在使用的图片

不带括号使用picture.size。

对于打印颜色,您发布的图片在PIL中具有“P”模式 ,这不是“RGB”模式,因此您得到零。

暂无
暂无

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

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