Example usage for java.awt Color getAlpha

List of usage examples for java.awt Color getAlpha

Introduction

In this page you can find the example usage for java.awt Color getAlpha.

Prototype

public int getAlpha() 

Source Link

Document

Returns the alpha component in the range 0-255.

Usage

From source file:Main.java

public static void main(String[] args) {
    Color myColor = Color.RED;

    System.out.println(myColor.getAlpha());

}

From source file:Main.java

public static int getAlpha(Color color) {
    return color.getAlpha();
}

From source file:ColorUtilities.java

public static Color blend(Color c0, Color c1) {
    double totalAlpha = c0.getAlpha() + c1.getAlpha();
    double weight0 = c0.getAlpha() / totalAlpha;
    double weight1 = c1.getAlpha() / totalAlpha;

    double r = weight0 * c0.getRed() + weight1 * c1.getRed();
    double g = weight0 * c0.getGreen() + weight1 * c1.getGreen();
    double b = weight0 * c0.getBlue() + weight1 * c1.getBlue();
    double a = Math.max(c0.getAlpha(), c1.getAlpha());

    return new Color((int) r, (int) g, (int) b, (int) a);
}

From source file:com.github.fritaly.graphml4j.Utils.java

/**
 * Encodes the given color into an hexadecimal string like "#RRGGBBAA" or
 * "#RRGGBB" (whether the transparency is set to 0).
 *
 * @param color//from   ww  w  .j a  va2s .  c  o m
 *            a color to encode. Can't be null.
 * @return a string representing the encoded color.
 */
static String encode(Color color) {
    Validate.notNull(color, "The given color is null");

    if (color.getAlpha() == 255) {
        return String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
    } else {
        return String.format("#%02X%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue(),
                color.getAlpha());
    }
}

From source file:ColorUtil.java

public static Color copy(Color c) {
    return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
}

From source file:Main.java

/**
 * Returns color copy.//from   w  w  w.  j ava2s  . c  o m
 *
 * @param color
 *            color to copy
 * @return color copy
 */
public static Color copy(final Color color) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}

From source file:Main.java

public static double getAlpha(Color color, Composite composite) {
    int trans = color.getTransparency();
    if ((trans == Color.TRANSLUCENT || trans == Color.BITMASK)) {
        return color.getAlpha() / 255d;
    }/*w w  w.j a v  a 2  s. c om*/
    if (composite instanceof AlphaComposite) {
        AlphaComposite ac = (AlphaComposite) composite;
        return ac.getAlpha();
    }
    return 1d;
}

From source file:chiliad.parser.pdf.model.MToken.java

public static String colorToRgba(Color c) {
    return "rgba(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() / 255 + ")";
}

From source file:Main.java

public static Color neighbour(Color c1, Color c2, double f) {
    return new Color(c1.getRed() + (int) ((c2.getRed() - c1.getRed()) * f),
            c1.getGreen() + (int) ((c2.getGreen() - c1.getGreen()) * f),
            c1.getBlue() + (int) ((c2.getBlue() - c1.getBlue()) * f),
            c1.getAlpha() + (int) ((c2.getAlpha() - c1.getAlpha()) * f));
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.Utils.java

public static String color2html(final Color c, final boolean alpha) {
    final String ac = Integer.toHexString(c.getAlpha()).toUpperCase(Locale.ENGLISH);
    final String rc = Integer.toHexString(c.getRed()).toUpperCase(Locale.ENGLISH);
    final String gc = Integer.toHexString(c.getGreen()).toUpperCase(Locale.ENGLISH);
    final String bc = Integer.toHexString(c.getBlue()).toUpperCase(Locale.ENGLISH);

    final StringBuilder result = new StringBuilder(7);
    result.append('#');
    if (alpha) {// w  ww  .  j av  a  2  s .  c om
        if (ac.length() == 1) {
            result.append('0');
        }
        result.append(ac);
    }
    if (rc.length() == 1) {
        result.append('0');
    }
    result.append(rc);
    if (gc.length() == 1) {
        result.append('0');
    }
    result.append(gc);
    if (bc.length() == 1) {
        result.append('0');
    }
    result.append(bc);

    return result.toString();
}