pixel components

D

devnew

hi
i was trying to get the rgb components of a pixel from an RGB jpeg
image
int pixels[]=new int[width*height];
bufferedimage.getRGB(0,0,width,height,pixels,0,width);

for(int x=0;x<pixels.length;x++){
int px=pixels[x];
int red=(px >> 16) & 0xFF;
int green=(px >> 8) & 0xFF;
int blue=(px) & 0xFF;
System.out.print("("+red+","+green+","+blue+") ");
this works and
a sample pixelvalue is =-6581359
with red,green,blue as 155,147,145

now what i want to know is

how can i get the orig int value (ie -6581359) from the components?
i am not quite sure about the bit shift/mask etc ..can anyone tell me
how to do this
dn
 
J

Joshua Cranmer

hi
i was trying to get the rgb components of a pixel from an RGB jpeg
image
int pixels[]=new int[width*height];
bufferedimage.getRGB(0,0,width,height,pixels,0,width);

for(int x=0;x<pixels.length;x++){
int px=pixels[x];
int red=(px >> 16) & 0xFF;
int green=(px >> 8) & 0xFF;
int blue=(px) & 0xFF;
System.out.print("("+red+","+green+","+blue+") ");
this works and
a sample pixelvalue is =-6581359
with red,green,blue as 155,147,145

now what i want to know is

how can i get the orig int value (ie -6581359) from the components?
i am not quite sure about the bit shift/mask etc ..can anyone tell me
how to do this
dn
The pixel value is the value of a packed-ARGB component (typically), so
that it will look like AARRGGBB (each letter represents a hexadecimal
digit). The alpha component is 0xff (fully opaque) here, which is why
you are getting a negative integer value. If you don't care about the
opacity, set it equal to 255 (0xff).

int px = (alpha << 24) | (red << 16) | (green << 8) | blue can reform a
pixel value, assuming that the values are already clipped to [0..255].
 
A

Andrew Thompson

Joshua Cranmer wrote:
...
i was trying to get the rgb components of a pixel from an RGB jpeg
...
The pixel value is the value of a packed-ARGB component (typically), so
that it will look like AARRGGBB (each letter represents a hexadecimal
digit). The alpha component is 0xff (fully opaque) here, which is why
you are getting a negative integer value. If you don't care about the
opacity, set it equal to 255 (0xff).

int px = (alpha << 24) | (red << 16) | (green << 8) | blue can reform a
pixel value, assuming that the values are already clipped to [0..255].

Well sh*t hey. These byte conversions still leave me
'flumoxed'. Don't suppose you'd care to share an SSCCE
that does what you are talking about - 'in code'?

(In case there is any misunderstanding, there is no sarcasm
intended in the above statements - but OTOH, I am drinking
Scotch, and still slightly irritated at the OP for *not* posting
compilable code..)

--
Andrew Thompson
http://www.athompson.info/andrew/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
 
L

Lew

Andrew said:
still slightly irritated at the OP for *not* posting
compilable code..)

In this case the question was about what idiom to use for an intended purpose,
not what was wrong with an existing snippet, so SSCCE didn't apply.
 
D

devnew

The alpha component is 0xff (fully opaque) here, which is why
you are getting a negative integer value. If you don't care about the
opacity, set it equal to 255 (0xff).

int px = (alpha << 24) | (red << 16) | (green << 8) | blue can reform a
pixel value, assuming that the values are already clipped to [0..255].


thanx joshua..
setting alpha=0xFF and then alpha << 24) | (red << 16) | (green << 8)
| blue gets me the orig value..

also
can anyone advise me where to get more about the color schemes and
bitlevel info ..i am a beginner to this area..
thanx again
dn
 
A

Andrew Thompson

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,995
Messages
2,570,236
Members
46,821
Latest member
AleidaSchi

Latest Threads

Top