Java Color Create color(float red, float green, float blue)

Here you can find the source of color(float red, float green, float blue)

Description

Unlike new Color(r,g,b).getRGB(), 1-epsilon rounds to brightest.

License

GNU General Public License

Declaration

public static int color(float red, float green, float blue) 

Method Source Code

//package com.java2s;

public class Main {
    /** Unlike new Color(r,g,b).getRGB(), 1-epsilon rounds to brightest.
    Truncates red, green, and blue into range 0 to 1 if needed.
    *///from www .  j  a v  a2s  .  com
    public static int color(float red, float green, float blue) {
        return 0xff000000 | (Math.max(0, Math.min((int) (red * 0x100), 0xff)) << 16)
                | (Math.max(0, Math.min((int) (green * 0x100), 0xff)) << 8)
                | Math.max(0, Math.min((int) (blue * 0x100), 0xff));
    }

    public static int color(float alpha, float red, float green, float blue) {
        return (Math.max(0, Math.min((int) (alpha * 0x100), 0xff)) << 24)
                | (Math.max(0, Math.min((int) (red * 0x100), 0xff)) << 16)
                | (Math.max(0, Math.min((int) (green * 0x100), 0xff)) << 8)
                | Math.max(0, Math.min((int) (blue * 0x100), 0xff));
    }
}

Related

  1. Color(int index)
  2. color(int red, int green, int blue, int alpha)
  3. color(int val)
  4. color(String color)