简体   繁体   English

我尝试使用PIL放置像素(RGB像素),但始终失败

[英]I Try to PutPixel (RGB pixel)using PIL ,But always Fail

I Try to using PIL.Image.putpixel(xy,color) ,But always fail. 我尝试使用PIL.Image.putpixel(xy,color),但总是失败。 It's work for put singel channel graycolor PIL.Image.putpixel((x,y),255) But I want to put RGB color to this picture. 它适用于放置singel通道灰度PIL.Image.putpixel((x,y),255)但我想将RGB颜色放置到此图片中。

trackback -> TypeError: function takes exactly 1 argument (3 given) 引用-> TypeError:函数正好接受1个参数(给定3个)

Not: 123.jpg is grayscale picture. 不是:123.jpg是灰度图片。

Code Below: 下面的代码:

from PIL import Image 
img = Image.open("123.jpg")
img.convert('RGB')
for x in range(img.size[0]):
    for y in range(img.size[1]):
        img.putpixel((x, y), (255, 255, 255))
img.save("temp.jpg")
img.show()

It should be 它应该是

img.putpixel(...)

(Change im to img) (将即时消息更改为img)

After correcting that, it should work. 更正该错误后,它应该可以工作。

The Image.convert() method returns an altered copy without changing the original, but you actually want to use the altered version, so replace: Image.convert()方法返回更改后的副本而不更改原始副本,但是您实际上要使用更改后的版本,因此请替换:

from PIL import Image 
img = Image.open("123.jpg")
img.convert('RGB')

with

from PIL import Image 
img = Image.open("123.jpg").convert('RGB')

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

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