PIL and getpixel()

D

devnew

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

thanx
dn
 
M

Marc 'BlackJack' Rintsch

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
 
D

devnew

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

thanx Marc

will try that
dn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,269
Latest member
vinaykumar_nevatia23

Latest Threads

Top