Example usage for android.graphics Color alpha

List of usage examples for android.graphics Color alpha

Introduction

In this page you can find the example usage for android.graphics Color alpha.

Prototype

@IntRange(from = 0, to = 255)
public static int alpha(int color) 

Source Link

Document

Return the alpha component of a color int.

Usage

From source file:Main.java

public static int blendColorsAlpha(int color1, int color2, float ratio) {
    final float inverseRatio = 1f - ratio;
    float a = (Color.alpha(color1) * ratio) + (Color.alpha(color2) * inverseRatio);
    float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRatio);
    float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRatio);
    float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRatio);
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}

From source file:Main.java

public static String getColorHexString(int color) {
    String colorHex = "#";
    String a = Integer.toHexString(Color.alpha(color));
    if (a.length() == 1)
        a = "0" + a;
    String r = Integer.toHexString(Color.red(color));
    if (r.length() == 1)
        r = "0" + r;
    String g = Integer.toHexString(Color.green(color));
    if (g.length() == 1)
        g = "0" + g;
    String b = Integer.toHexString(Color.blue(color));
    if (b.length() == 1)
        b = "0" + b;
    colorHex += a + r + g + b;/*from   www .ja  v  a2s . c  o  m*/
    return colorHex;
}

From source file:Main.java

public static String getARGBstring(Bitmap bitmap, int x, int y) {
    return "ARGB at " + x + "," + y + " is \t\tA " + String.format("%03d", Color.alpha(bitmap.getPixel(x, y)))
            + "\t\tR " + String.format("%03d", Color.red(bitmap.getPixel(x, y))) + "\t\tG "
            + String.format("%03d", Color.green(bitmap.getPixel(x, y))) + "\t\tB "
            + String.format("%03d", Color.blue(bitmap.getPixel(x, y)));
}

From source file:Main.java

public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * DARKEN_SATURATION, 1.0f);
    hsv[2] = hsv[2] * DARKEN_INTENSITY;//from w w w  . j av a  2s . co m
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}

From source file:Main.java

public static int darkenColor(int color) {
    float[] hsv = new float[3];
    int alpha = Color.alpha(color);
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1] * SATURATION_DARKEN, 1.0f);
    hsv[2] = hsv[2] * INTENSITY_DARKEN;/*  w w  w .j a va2 s. c om*/
    int tempColor = Color.HSVToColor(hsv);
    return Color.argb(alpha, Color.red(tempColor), Color.green(tempColor), Color.blue(tempColor));
}

From source file:Main.java

public static int adjustAlpha(int color, float factor) {
    int alpha = Math.round(Color.alpha(color) * factor);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);

    return Color.argb(alpha, red, green, blue);
}

From source file:Main.java

public static int saturate(int color, float saturation) {
    float[] hsv = new float[3];
    Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsv);
    hsv[1] = saturation;/*from w w w. j  ava2s.  c  om*/
    return Color.HSVToColor(Color.alpha(color), hsv);
}

From source file:Main.java

public static int brighten(int color, float brightness) {
    float[] hsv = new float[3];
    Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsv);
    hsv[2] = brightness;//  www .  j a v  a2  s. c  o m
    return Color.HSVToColor(Color.alpha(color), hsv);
}

From source file:Main.java

/**
 * Composite two potentially translucent colors over each other and returns the result.
 */// w  w  w  .  j a  va 2s  .  c om
public static int compositeColors(int fg, int bg) {
    final float alpha1 = Color.alpha(fg) / 255f;
    final float alpha2 = Color.alpha(bg) / 255f;

    float a = (alpha1 + alpha2) * (1f - alpha1);
    float r = (Color.red(fg) * alpha1) + (Color.red(bg) * alpha2 * (1f - alpha1));
    float g = (Color.green(fg) * alpha1) + (Color.green(bg) * alpha2 * (1f - alpha1));
    float b = (Color.blue(fg) * alpha1) + (Color.blue(bg) * alpha2 * (1f - alpha1));

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

From source file:Main.java

private static int getGradientColor(int startColor, int endColor, float radio) {
    if (radio <= 0.000001)
        return startColor;
    if (radio >= 1.0)
        return endColor;

    int a1 = Color.alpha(startColor);
    int r1 = Color.red(startColor);
    int g1 = Color.green(startColor);
    int b1 = Color.blue(startColor);

    int a2 = Color.alpha(endColor);
    int r2 = Color.red(endColor);
    int g2 = Color.green(endColor);
    int b2 = Color.blue(endColor);

    int a3 = (int) (a1 + (a2 - a1) * radio);
    int r3 = (int) (r1 + (r2 - r1) * radio);
    int g3 = (int) (g1 + (g2 - g1) * radio);
    int b3 = (int) (b1 + (b2 - b1) * radio);

    return Color.argb(a3, r3, g3, b3);
}