1

I'm having some issues getting the RGB values of a bitmap in Android... This is what I'm doing:

int[] temp = new int[width*height];
bit.getPixels(temp, 0, width, 0, 0, width, height);

However, the colors don't seem to match the typical RGB values. For example, a white pixel will show up as -1, whereas the RGB value for it is 16777215. (I'm getting that value from this website: http://www.shodor.org/stella2java/rgbint.html)

There's also a ton of negative values which don't seem to fit normal RGB values. My question is if there is a way to convert to the typical RGB values as opposed to the Android Color integers which the getPixels() method returns. Thanks for any help and let me know if you have any questions.

3 Answers 3

1

Maybe you can try getPixel first, seems like it would be easier.

Otherwise, can you give more code in your question (how do you declare the bitmap, where you get that -1 value from...etc...)

Sign up to request clarification or add additional context in comments.

Comments

1

According to the documentation, -1 is White, and really, 16777215 is 0xffffff in hex, which is equivalent to -1.

All of the numbers for Color's are negative, because there is the leading f in the hexadecimal value. There is the leading ff in the hexadecimal value to specify the alpha value, or the opacity. If a color is completely opaque, then the number will lead with ff, if the color is completely transparent, the number will lead with 00.

1 Comment

The thing is that I need the positive values of these numbers. Is there any way to get them easily?
1

Store the value in an unsigned integer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.