Java Utililty Methods RGB Color Create

List of utility methods to do RGB Color Create

Description

The list of methods to do RGB Color Create are organized into topic(s).

Method

int[]toRGB(int color)
to RGB
int[] rgb = new int[3];
toRGB(color, rgb);
return rgb;
inttoRgb(int r, int g, int b)
to Rgb
return r << 16 | g << 8 | b;
int[]toRGB(String hexString)
to RGB
if (hexString.startsWith("0x")) {
    hexString = hexString.substring(2);
} else if (hexString.startsWith("#")) {
    hexString = hexString.substring(1);
int value = Integer.parseInt(hexString, 16);
return toRGB(value);
inttoRGB15(int x)
Converts a color from RGB24 to RGB15
int r = (x >> 16) & 0xFF;
int g = (x >> 8) & 0xFF;
int b = (x) & 0xFF;
int a = (x >> 24) & 0xFF;
r = r >> 3;
g = g >> 3;
b = b >> 3;
return r | (g << 5) | (b << 10) | (1 << 15);
...
inttoRGBA(float[] colors)
to RGBA
if (colors.length != 4)
    throw new IllegalArgumentException("colors[] must have a length of 4!");
return toRGBA(colors[0], colors[1], colors[2], colors[3]);
inttoRGBA(int argb)
Converts AARRGGBB to RRGGBBAA
return ((argb << 8) & 0xFFFFFF00) | ((argb >> 24) & 0xFF);
int[]toRGBA(int color)
to RGBA
int alpha = color >> 24 & 255;
int red = color >> 16 & 255;
int green = color >> 8 & 255;
int blue = color & 255;
return new int[] { red, green, blue, alpha };
StringtoRGBA(String hexARGB)
to RGBA
int rgba[] = new int[3];
rgba[0] = Integer.parseInt(hexARGB.substring(2, 4), 16);
rgba[1] = Integer.parseInt(hexARGB.substring(4, 6), 16);
rgba[2] = Integer.parseInt(hexARGB.substring(6), 16);
float alpha = Integer.parseInt(hexARGB.substring(0, 2), 16);
return buildRgba(rgba, alpha);
int[]toRGBAArray(int colorBuffer)
to RGBA Array
return new int[] { (colorBuffer >> 16 & 255), (colorBuffer >> 8 & 255), (colorBuffer & 255),
        (colorBuffer >> 24 & 255) };
int[]toRGBAIntArray(long argb)
to RGBA Int Array
return toIntArray(toRGBA(argb));