Color ARGB woes
2009 February 5
Here is a simple Helper-Method for converting compact RGB-Values into single RGB-Values and vice versa. Works with alpha values too, for 32 bit color images.
private static int[] getARGB(int rgb) {
int[] value = new int[4];
// alpha
value[0] = (rgb >> 24) & 0xFF;
// red
value[1] = (rgb >> 16) & 0xFF;
// green
value[2] = (rgb >> 8 ) & 0xFF;
// blue
value[3] = (rgb) & 0xFF;
return value;
}
private static int getARGB(int a, int r, int g, int b) {
int rgb = ((a & 0xFF) << 24) |
((r & 0xFF) << 16) |
((g & 0xFF) << 8 ) |
((b & 0xFF));
return rgb;
}
I love bitshifting…