Example usage for android.graphics Color argb

List of usage examples for android.graphics Color argb

Introduction

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

Prototype

@ColorInt
public static int argb(float alpha, float red, float green, float blue) 

Source Link

Document

Return a color-int from alpha, red, green, blue float components in the range \([0..1]\).

Usage

From source file:Main.java

public static Bitmap boost(Bitmap src, int type, float percent) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());

    int A, R, G, B;
    int pixel;//www.ja v  a2 s  . c  o m

    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            if (type == 1) {
                R = (int) (R * (1 + percent));
                if (R > 255)
                    R = 255;
            } else if (type == 2) {
                G = (int) (G * (1 + percent));
                if (G > 255)
                    G = 255;
            } else if (type == 3) {
                B = (int) (B * (1 + percent));
                if (B > 255)
                    B = 255;
            }
            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}

From source file:Main.java

static public int getFlightCategoryColor(String flightCategory) {
    int color = 0;
    if (flightCategory.equals(CATEGORY_VFR)) {
        color = Color.argb(255, 0, 160, 32);
    } else if (flightCategory.equals(CATEGORY_MVFR)) {
        color = Color.argb(255, 0, 144, 224);
    } else if (flightCategory.equals(CATEGORY_IFR)) {
        color = Color.argb(255, 192, 32, 0);
    } else if (flightCategory.equals(CATEGORY_LIFR)) {
        color = Color.argb(255, 200, 0, 160);
    }//  ww w. j av a2s .  c o m
    return color;
}

From source file:Main.java

public static int setDarkColor(int color, int factor) {
    int red = Color.red(color) - factor;
    int green = Color.green(color) - factor;
    int blue = Color.blue(color) - factor;
    if (factor < 0) {
        red = (red > 0xff) ? 0xff : red;
        green = (green > 0xff) ? 0xff : green;
        blue = (blue > 0xff) ? 0xff : blue;
        if (red == 0xff && green == 0xff && blue == 0xff) {
            red = factor;//from   w  w  w. j av a  2 s  .  c  om
            green = factor;
            blue = factor;
        }
    }
    if (factor > 0) {
        red = (red < 0) ? 0 : red;
        green = (green < 0) ? 0 : green;
        blue = (blue < 0) ? 0 : blue;
        if (red == 0 && green == 0 && blue == 0) {
            red = factor;
            green = factor;
            blue = factor;
        }
    }
    return Color.argb(0xff, red, green, blue);
}

From source file:Main.java

public static Bitmap handleImagePixelsOldPhoto(Bitmap bm) {
    Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    int width = bm.getWidth();
    int height = bm.getHeight();
    int color = 0;
    int r, g, b, a, r1, g1, b1;

    int[] oldPx = new int[width * height];
    int[] newPx = new int[width * height];

    bm.getPixels(oldPx, 0, bm.getWidth(), 0, 0, width, height);
    for (int i = 0; i < width * height; i++) {
        color = oldPx[i];//from   w ww .  ja  va2s .c  o m
        a = Color.alpha(color);
        r = Color.red(color);
        g = Color.green(color);
        b = Color.blue(color);

        r1 = (int) (0.393 * r + 0.769 * g + 0.189 * b);
        g1 = (int) (0.349 * r + 0.686 * g + 0.168 * b);
        b1 = (int) (0.272 * r + 0.534 * g + 0.131 * b);

        if (r1 > 255) {
            r1 = 255;
        }
        if (g1 > 255) {
            g1 = 255;
        }
        if (b1 > 255) {
            b1 = 255;
        }

        newPx[i] = Color.argb(a, r1, g1, b1);
    }
    bmp.setPixels(newPx, 0, width, 0, 0, width, height);
    return bmp;
}

From source file:Main.java

/**
 * Append an alpha value to the given color.
 * //  ww w. j  a va 2  s. c o m
 * @param color
 * @param alpha a 0.0 to a 1.0 alpha value (will be translated to 0-255)
 * @return The new color value.
 */
public static int colorWithAlpha(int color, float alpha) {
    if (alpha < 0f) {
        alpha = 0f;
    } else if (alpha > 1f) {
        alpha = 1f;
    }
    return Color.argb((int) (alpha * 255), Color.red(color), Color.green(color), Color.blue(color));
}

From source file:Main.java

public static Bitmap handleImageNegative(Bitmap bm) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    int color;//w ww.jav  a2s  . c  om
    int r, g, b, a;
    Bitmap bmp = Bitmap.createBitmap(bm.getWidth(), bm.getHeight(), Bitmap.Config.ARGB_8888);
    int[] oldPx = new int[width * height];
    int[] newPx = new int[width * height];
    bm.getPixels(oldPx, 0, width, 0, 0, width, height);
    for (int i = 0; i < width * height; i++) {
        color = oldPx[i];
        r = Color.red(color);
        g = Color.green(color);
        b = Color.blue(color);
        a = Color.alpha(color);

        r = 255 - r;
        g = 255 - g;
        b = 255 - b;
        if (r > 255) {
            r = 255;
        } else if (r < 0) {
            r = 0;
        }
        if (g > 255) {
            g = 255;
        } else if (g < 0) {
            g = 0;
        }
        if (b > 255) {
            b = 255;
        } else if (b < 0) {
            b = 0;
        }
        newPx[i] = Color.argb(a, r, g, b);
    }
    bmp.setPixels(newPx, 0, width, 0, 0, width, height);
    return bmp;

}

From source file:Main.java

/**
 * Linearly interpolate the RGB from color {@code a} to color {@code b}.  Alpha values are
 * ignored, and the resulting alpha is always opaque.
 *
 * @param a The start color, or the result if the {@code ratio} is 0.0.
 * @param b The end color, or the result if the {@code ratio} is 1.0.
 * @param ratio The ratio of {@code b}'s influence in the result, between 0.0 to 1.0.
 * @return The computed blend color as an integer.
 *//*from   w  w  w.  ja  v a  2s.  c om*/
public static int blendRGB(int a, int b, float ratio) {
    return Color.argb(ALPHA_OPAQUE, clampedLerp(Color.red(a), Color.red(b), ratio),
            clampedLerp(Color.green(a), Color.green(b), ratio),
            clampedLerp(Color.blue(a), Color.blue(b), ratio));
}

From source file:Main.java

public static Bitmap doSherpiaEffect(Bitmap src, int depth, double red, double green, double blue) {
    int width = src.getWidth();
    int height = src.getHeight();
    Bitmap bmOut = Bitmap.createBitmap(width, height, src.getConfig());
    final double GS_RED = 0.3;
    final double GS_GREEN = 0.59;
    final double GS_BLUE = 0.11;
    int A, R, G, B;
    int pixel;//w  w  w .ja v  a2s  .com

    for (int x = 0; x < width; ++x) {
        for (int y = 0; y < height; ++y) {
            pixel = src.getPixel(x, y);
            A = Color.alpha(pixel);
            R = Color.red(pixel);
            G = Color.green(pixel);
            B = Color.blue(pixel);
            B = G = R = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B);

            R += (depth * red);
            if (R > 255) {
                R = 255;
            }

            G += (depth * green);
            if (G > 255) {
                G = 255;
            }

            B += (depth * blue);
            if (B > 255) {
                B = 255;
            }

            bmOut.setPixel(x, y, Color.argb(A, R, G, B));
        }
    }
    return bmOut;
}

From source file:Main.java

public static Bitmap backsheetImage(Bitmap bm) {

    int width = bm.getWidth();
    int height = bm.getHeight();
    int color;//  www . j a  v a 2 s  .  com
    int r, g, b, a;

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    int[] oldPx = new int[width * height];
    int[] newPx = new int[width * height];

    bm.getPixels(oldPx, 0, width, 0, 0, width, height);

    for (int i = 0; i < oldPx.length; i++) {
        color = oldPx[i];
        r = Color.red(color);
        g = Color.green(color);
        b = Color.blue(color);
        a = Color.alpha(color);

        r = 255 - r;
        g = 255 - g;
        b = 255 - b;

        if (r > 255) {
            r = 255;
        } else if (r < 0) {
            r = 0;
        }

        if (g > 255) {
            g = 255;
        } else if (g < 0) {
            g = 0;
        }

        if (b > 255) {
            b = 255;
        } else if (b < 0) {
            b = 0;
        }

        newPx[i] = Color.argb(a, r, g, b);
    }

    bitmap.setPixels(newPx, 0, width, 0, 0, width, height);
    return bitmap;
}

From source file:Main.java

/**
 * Lightens a color by a given factor.//from ww  w .  j  a  v a 2s.  co  m
 *
 * @param color
 *            The color to lighten
 * @param factor
 *            The factor to lighten the color. 0 will make the color unchanged. 1 will make the
 *            color white.
 * @return lighter version of the specified color.
 */
public static int lighten(int color, float factor) {
    int red = (int) ((Color.red(color) * (1 - factor) / 255 + factor) * 255);
    int green = (int) ((Color.green(color) * (1 - factor) / 255 + factor) * 255);
    int blue = (int) ((Color.blue(color) * (1 - factor) / 255 + factor) * 255);
    return Color.argb(Color.alpha(color), red, green, blue);
}