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

float[][]rgb2grayscale(int[] rgb, int imageWidth, int imageHeight)
rgbgrayscale
float[][] grayscale = new float[imageHeight][imageWidth];
for (int i = 0, index = 0; i < imageHeight; i++) {
    for (int j = 0; j < imageWidth; j++, index++) {
        grayscale[i][j] = (float) (((rgb[index] >> 16) & 0xff) * 0.2126
                + ((rgb[index] >> 8) & 0xff) * 0.7152 + (rgb[index] & 0xff) * 0.0722 - 128.0);
return grayscale;
...
byte[]rgb2grayscaleA(int[] rgb)
rgbgrayscale A
byte[] grayscale = new byte[rgb.length << 1];
for (int i = 0, j = 0; i < rgb.length; i++) {
    grayscale[j++] = (byte) (((rgb[i] >> 16) & 0xff) * 0.2126 + ((rgb[i] >> 8) & 0xff) * 0.7152
            + (rgb[i] & 0xff) * 0.0722);
    grayscale[j++] = (byte) ((rgb[i] >> 24) & 0xff);
return grayscale;
Stringrgb2Hex(int rgb)
rgb Hex
StringBuffer sb = new StringBuffer();
for (int i = 5; i >= 0; i--) {
    int shift = i * 4;
    int n = (rgb & (15 << shift)) >> shift;
    sb.append(HEX[n % 16]);
return sb.toString();
Stringrgb2hex(int[] rgb)
rgbhex
return toHex(rgb[0]) + toHex(rgb[1]) + toHex(rgb[2]);
double[]rgb2hsl(int colour)
rgbhsl
return rgb2hsl(red(colour), green(colour), blue(colour));
voidRGB2HSL(int red, int green, int blue, float[] hslvals)
RGBHSL
float r = red / 255.f;
float g = green / 255.f;
float b = blue / 255.f;
float max = Math.max(Math.max(r, g), b);
float min = Math.min(Math.min(r, g), b);
float c = max - min;
float h_ = 0.f;
if (c == 0) {
...
int[]rgb2hsl(int[] rgb)
rgbhsl
double max = Math.max(Math.max(rgb[0], rgb[1]), rgb[2]); 
double delta = max - Math.min(Math.min(rgb[0], rgb[1]), rgb[2]); 
double h = 0;
int s = 0;
int l = (int) Math.round(max * 100d / 255d); 
if (max != 0) {
    s = (int) Math.round(delta * 100d / max); 
    if (max == rgb[0]) {
...
float[]rgb2hsv(int r, int g, int b)
rgbhsv
float r1 = ((float) r) / 255;
float g1 = ((float) g) / 255;
float b1 = ((float) b) / 255;
float cMax = max(r1, g1, b1);
float cMin = min(r1, g1, b1);
float delta = cMax - cMin;
float h = 0, s = 0, v = 0;
if (delta == 0) {
...
intrgb2int(final int[] color)
rgbint
return (color[0] << 16) + (color[1] << 8) + color[2];
intrgb2intval(int r, int g, int b)
rgbintval
int temp = 0xff000000 | (r << 16) | (g << 8) | b;
return temp;