I obtain pixel color by
int color = image.getRGB(x,y);
then i want to acquire red, green, blue components separately. How to do that? Maybe using some bitmask?
int green = color&0x00ff00;
apparently not working... :(
To get color components you can use:
import android.graphics.Color;
int r = Color.red(intColor);
int g = Color.green(intColor);
int b = Color.blue(intColor);
int a = Color.alpha(intColor);
int value = image.getRGB(x,y);
R = (byte)(value & 0x000000FF);
G = (byte)((value & 0x0000FF00) >> 8);
B = (byte)((value & 0x00FF0000) >> 16);
A = (byte)((value & 0xFF000000) >> 24);
May need to flip the R, A, or B around.
You forgot to shift the byte to the right:
int green = (color & 0x00ff00) >> 8;
You can use Color
constructor and pass the given integer and hasalpha=true
:
Color color = new Color(image.getRGB(x,y), true);
getRGB returns the color of type TYPE_INT_ARGB which means it has an alpha channel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With