Putpixel question

I use the putpixel operation on the image (srcImage), which is equal to w = 134 and h = 454

Here we enter the r, g, b value of the part of the font that is 0.255.0, which I found by debugging (using the print option).

image = letters['H'] r,g,b = image.getpixel((1,1)) *Note rgb values are 0, 255,0* srcImage.putpixel((10,15),(r,g,b)) srcImage.save('lolmini2.jpg') 

This code does not give any error, but when I look at the saved image, I can not determine the clear green pixel.

+4
source share
2 answers

Instead of using putpixel() and getpixel() , you should use indexing instead. For getpixel() you can use pixesl[1, 1] , and for putpixel you can use pixels[1, 1] = (r, g, b) . It should work the same way, but much faster. pixels here image.load()

However, I do not understand why this will not work. It should work without problems. Maybe jpeg compression is killing you here. Did you try to save it as a png / gif file? Or set more than 1 pixel.

+5
source

I know this is a very old post, but for beginners who would like to stick with putpixels() for a while, here is a solution:

initialize the image variable as:

 from PIL import Image img = Image.new('RGB', [200,200], 0x000000) 

Be sure to initialize it as β€œRGB” if you want to control RGB values.

Sometimes people initialize images as:

 img = Image.new('I', [200, 200], 0x000000) 

and then try working with RGB values ​​that don't work .

0
source

All Articles