Convert int colours to argb

179 views Asked by At
public static int getARGB(final int red, final int green, final int blue, final int alpha) {
        int argb = (alpha<<24)|(red<<16)|(green<<8)|blue;
        return argb;
    }

So I have to convert the different colour ints to an argb value. Is the way I have done correct?

1

There are 1 answers

5
Ahmad On

You should also add a mask to each input to make sure they are not greater than 0xFF:

int argb = (0xFF & alpha) << 24 | (0xFF & red) << 16 | (0xFF & green) << 8 | (0xFF & blue)