471,348 Members | 1,316 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

PIL and getpixel()

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

Oct 16 '07 #1
2 21463
On Tue, 16 Oct 2007 07:05:56 +0000, de****@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
Oct 16 '07 #2
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

Oct 16 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by C. Alexander | last post: by
7 posts views Thread by Serdar C. | last post: by
reply views Thread by OHM \( One Handed Man \) | last post: by
1 post views Thread by aniketpatil | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.