Java Utililty Methods Color Create

List of utility methods to do Color Create

Description

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

Method

intcolorFromRGB(int r, int g, int b)
color From RGB
return (r * 65536) + (g * 256) + b;
intcolorFromRGB(int red, int green, int blue)
color From RGB
int newPixel = 0;
int alpha = 1;
newPixel += alpha;
newPixel = newPixel << 8;
newPixel += red;
newPixel = newPixel << 8;
newPixel += green;
newPixel = newPixel << 8;
...
intcolorFromRGBA(int red, int green, int blue, int alpha)
Convert R, G, B, Alpha to standard 8 bit
int newPixel = 0;
newPixel += alpha;
newPixel = newPixel << 8;
newPixel += red;
newPixel = newPixel << 8;
newPixel += green;
newPixel = newPixel << 8;
newPixel += blue;
...
intcolorFromString(String string)
Gets the color as int value from the given String .
if (string == null || string.length() == 0) {
    return 0x000000ff;
String padded = "";
if (string.length() == 6) {
    padded = string + "ff";
} else if (string.length() > 8) {
    padded = string.substring(0, 8);
...
intcolorWithARGB(int alpha, int red, int green, int blue)
color With ARGB
return (alpha << 24) | (red << 16) | (green << 8) | blue;
intcolorWithIntAndAlpha(int color, int alpha)
color With Int And Alpha
return (color & 0xffffff) | (alpha << 24);
ImagegenerateBlankImage(int w, int h, Color col)
generate Blank Image
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = (Graphics2D) img.getGraphics();
g2.setBackground(col);
g2.clearRect(0, 0, w, h);
return img;
ColorgenerateColor(int fc, int bc)
generate Color
Random random = new Random();
if (fc > 255)
    fc = 255;
if (bc > 255)
    bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
...
intgenerateColorFromString(String seed)
generate Color From String
Random rand = new Random(seed.hashCode());
int red = rand.nextInt(256);
int green = rand.nextInt(256);
int blue = rand.nextInt(256);
return new Color(red, green, blue).getRGB();
ColorModelgenerateColorModel()
generate Color Model
byte[] r = new byte[255];
byte[] g = new byte[255];
byte[] b = new byte[255];
for (int i = 0; i < 255; i++) {
    r[i] = (byte) ((i * 26) % 250);
    g[i] = (byte) ((i * 2) % 250);
    b[i] = (byte) ((i * 35) % 250);
return new IndexColorModel(8, 255, r, g, b);