Converting pixel value (byte) to integer value

i have used the pixelgrabber to grab pixels. When i tried to work on the individual pixel value from the integer array i found the values were actually byte values something like  (-7697782). I tried to type cast these byte values to integer. It works for certain values but for certain values i get only negative value (like -180 for -7697782). How do i convert the pixel array values to numbers within the range 0 to 255. or else how do i get an integer RGB value of a pixel within the range 0 to 255.

Someone help me in this regard.
Grattitudes.
itmaniacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TimYatesCommented:
>  found the values were actually byte values something like  (-7697782)

This can't be a byte...it's too big...

What code are you using?  If you are loading the image with a Paletted ColorModel, then you will be getting palette entries back, not RGB colors...

Otherwise, you should have an array of int, then get the colors like:

int alpha = ( color & 0xFF000000 ) >> 24 ;
int red = ( color & 0xFF0000 ) >> 16 ;
int green = ( color & 0xFF00 ) >> 8 ;
int blue = ( color & 0xFF ) ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
'byte' need not be cast to 'int'. If ever required, the conversion will be done automatically, because 'int' has more range than 'byte' and by default, 'byte' and 'short' are always converted to 'int' in expressions.

byte a = 5 ;
int b ;
b = a ; // valid - 'int' has larger storage and both are compatible types
b = ( int ) a ; // the (cast) is actually not required

Mayank.
0
CleanupPingCommented:
itmaniac:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

jimmackCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Delete - No refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0
Mayank SAssociate Director - Product EngineeringCommented:
I would say: Split between TimYates and mayankeagle - their explanations are enough as per the questioner's requirements.
0
jimmackCommented:
OK.  Thanks Mayank ;-)

Correction posted to cleanup:  Split between TimYates and mayankeagle.
0
Mayank SAssociate Director - Product EngineeringCommented:
Please go ahead.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.