Java Utililty Methods RGB Color Convert To

List of utility methods to do RGB Color Convert To

Description

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

Method

intrgbaToColor(int r, int g, int b, int a)
rgba To Color
return ((a << 24) & 0xFF000000) | ((r << 16) & 0xFF0000) | ((g << 8) & 0xFF00) | (b & 0xFF);
StringrgbaToHex(String color)
rgba To Hex
if (isHexColor(color)) {
    return color;
String f = color.substring("rgba(".length());
int l = f.lastIndexOf(",");
if (l == -1) {
    return color;
String t = f.substring(0, l);
String[] rgb = t.split(",");
int r = Integer.parseInt(rgb[0], 10);
int g = Integer.parseInt(rgb[1], 10);
int b = Integer.parseInt(rgb[2], 10);
String rColor = Integer.toHexString(r);
if (rColor.length() < 2) {
    rColor = "0" + r;
String gColor = Integer.toHexString(g);
if (gColor.length() < 2) {
    gColor = "0" + g;
String bColor = Integer.toHexString(b);
if (bColor.length() < 2) {
    bColor = "0" + b;
return "#" + rColor + gColor + bColor;
intRGBAtoI(byte r, byte g, byte b, byte a)
RGB Ato I
return (((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | b);
StringrgbBitfieldToString(int rgb)
Extracts the red green and blue portions as of a pixel and returns them as String.
return getRed(rgb) + " " + getGreen(rgb) + " " + getBlue(rgb);
byte[]rgbToBgr(final byte[] pixels)
Convert an image data array in RGB order to BGR or vice versa.
final byte[] pixels_publish = new byte[pixels.length];
int idx = 0;
for (int i = 0; i < pixels.length / 3; i++) {
    pixels_publish[idx] = pixels[idx + 2];
    pixels_publish[idx + 1] = pixels[idx + 1];
    pixels_publish[idx + 2] = pixels[idx];
    idx += 3;
return pixels_publish;
StringRGBtoBGR(String color)
Converts RGB (ARBG) color to BGR (ABGR).
if (color.length() == 6) {
    color = "FF" + color;
if (color.length() == 8) {
    return color.substring(0, 2) + color.substring(6, 8) + color.substring(4, 6) + color.substring(2, 4);
return color;
booleanrgbToBlackWhite(int pix, int threshold)
rgb To Black White
final int r = (pix >> 16) & 0xff;
final int g = (pix >> 8) & 0xff;
final int b = (pix >> 0) & 0xff;
final int intensity = ((r * 306) + (g * 601) + (b * 117)) >> 10;
return (intensity > threshold); 
intrgbToColor(int r, int g, int b)
rgb To Color
return argbToColor(255, r, g, b);
intrgbToDecimal(int r, int g, int b)
rgb To Decimal
return b + 256 * g + 65536 * r;
intrgbToGray(int colorIn)
Change an RGB color to a gray value.
int red = (colorIn & RED_MASK) >> RED_OFFSET; 
int green = (colorIn & GREEN_MASK) >> GREEN_OFFSET; 
int blue = colorIn & BLUE_MASK; 
double brightness = 0.3 * red + 0.59 * green + 0.11 * blue;
return (int) brightness;