> What does "characterRun.getColor()" return? How can I convert it to RGB?
I know this is an old post, but I recently needed the same thing.
>From what I can tell, getIco24() returns what the ms specs call a colorRef (24
>bit color) BBGGRR format instead of RRGGBB. I have been experimenting with
>some methods to convert that value to rgb or hex. Not highly tested, they seem
>to be working so far.
Caveat, I could not figure out how to handle the "Auto" color, so the methods
return black for "Auto".
HTH
Leigh
public static int[] ico24ToRGB(int ico24) {
int[] rgb = new int[3];
// If the colorRef is not "Auto", unpack the rgb values
if (ico24 != -1) {
rgb[0] = (ico24 >> 0) & 0xff; // red;
rgb[1] = (ico24 >> 8) & 0xff; // green
rgb[2] = (ico24 >> 16) & 0xff; // blue
}
return rgb;
}
public static String ico24AsHex(int ico24) {
return Integer.toHexString(ico24);
}
public static String ico24ToHex(int ico24) {
int r = (ico24 >> 0) & 0xff; // red;
int g = (ico24 >> 8) & 0xff; // green
int b = (ico24 >> 16) & 0xff; // blue
int rgb = (r << 16) | (g << 8) | b;
// Hack. Find a better way to maintain leading zeroes
return Integer.toHexString(0xC000000 | rgb).substring(1);
}
public static int hexToIco24(String hexColor) {
if (hexColor == null || hexColor.length() != 6) {
throw new IllegalArgumentException("hexColor must be 6 characters in
length. Example: ffffff");
}
int r = Integer.parseInt(hexColor.substring(0, 2), 16);
int g = Integer.parseInt(hexColor.substring(2, 4), 16);
int b = Integer.parseInt(hexColor.substring(4, 6), 16);
return rgbToIco24(r, g, b);
}
public static int rgbToIco24(int r, int g, int b) {
return (0xff << 24) | (b << 16) | (g << 8) | r;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]