PIL and getpixel()

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Tue Oct 16 03:15:50 EDT 2007


On Tue, 16 Oct 2007 07:05:56 +0000, devnew at gmail.com wrote:

> i am trying to get the pixel data using im.getpixel()
> i am getting a tuple like (152,118,106) for a pixel in a RGB jpeg
> image .
> what i really want is an integer value representing a pixel ,like waht
> i can get from java's BufferedImage.getRGB(x,y) ..
> 
> i am wondering if someone can advise me on how i can do this

Just pack the RGB values into an `int` by shifting and or-ing.  Untested:

red, green, blue = img.getpixel(x, y)
pixel_as_int = red << 16 | green << 8 | blue

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list