简体   繁体   中英

PIL writing pixels in redscale rather than grayscale

I am using PIL to make pictures pixel by pixel. I notice that while I am specifying various shades of gray to my input, the output image is always in various shades of red. For example, I would assume that the following:

im = Image.new("RGB", (100, 100), "black")
im.putpixel((1,9), ImageColor.getcolor('rgb(255,255,255)', '1'))
im.putpixel((1,1), ImageColor.getcolor('rgb(55,55,55)', '1'))
im.save('test.png')

would create one gray pixel and one white pixel, however this creates two red pixels, with the "gray" pixel being a darker shade of red (see below). Why is this happening and how can I get the expected output of a gray and white pixel.

两个红色像素,而不是一个灰色和白色像素

This works for me:

im = Image.new("RGB",(100,100))
im.putpixel((1,9), (255,255,255))
im.putpixel((1,1), (55,55,55))
im.save("test.png")

Resulting Image:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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