Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Converting pixel value (byte) to integer value

Posted on 2003-03-30
8
Medium Priority
?
729 Views
Last Modified: 2008-03-10
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.
0
Comment
Question by:itmaniac
7 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 252 total points
ID: 8235298
>  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
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 248 total points
ID: 8236970
'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
 

Expert Comment

by:CleanupPing
ID: 9058389
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:jimmack
ID: 9735655
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 9738146
I would say: Split between TimYates and mayankeagle - their explanations are enough as per the questioner's requirements.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9738164
OK.  Thanks Mayank ;-)

Correction posted to cleanup:  Split between TimYates and mayankeagle.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9738177
Please go ahead.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question