Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

pixel components

Thread view: 
devnew@gmail.com - 20 Oct 2007 09:45 GMT
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
Joshua Cranmer - 20 Oct 2007 14:30 GMT
> hi
> i was trying to get the rgb components of a pixel from an RGB jpeg
[quoted text clipped - 18 lines]
> 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].

Signature

Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

Andrew Thompson - 20 Oct 2007 15:08 GMT
...
>> 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
[quoted text clipped - 4 lines]
>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..)

Signature

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

Lew - 20 Oct 2007 15:18 GMT
> 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.

Signature

Lew

Andrew Thompson - 21 Oct 2007 03:28 GMT
>> 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.

Agreed.  In fact that was probably the source of my
(mild) irritation.  I'd have mucked about with the code
if the problem *had* justified an SSCCE, and included
runnable code!

Signature

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

devnew@gmail.com - 20 Oct 2007 18:06 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.