Convert int color to int components

I get the color of the pixel

int color = image.getRGB(x,y);

then I want to purchase the red, green, blue components separately. How to do it? Maybe with some bitmask?

int green = color&0x00ff00;

obviously does not work ...: (

+5
source share
4 answers

To get the 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);
+26
source
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);

You may need to flip R, A, or B around.

+4
source

:

int green = (color & 0x00ff00) >> 8;
+3

Color hasalpha=true:

Color color = new Color(image.getRGB(x,y), true);

getRGB TYPE_INT_ARGB, , -.

+2

All Articles