List of usage examples for android.graphics Color argb
@ColorInt public static int argb(float alpha, float red, float green, float blue)
From source file:Main.java
public static int lighten(int color) { double r = Color.red(color); double g = Color.green(color); double b = Color.blue(color); r *= 1.1;/* w w w.ja v a 2 s . c o m*/ g *= 1.1; b *= 1.1; double threshold = 255.999; double max = Math.max(r, Math.max(g, b)); if (max > threshold) { double total = r + g + b; if (total >= 3 * threshold) return Color.WHITE; double x = (3 * threshold - total) / (3 * max - total); double gray = threshold - x * max; r = gray + x * r; g = gray + x * g; b = gray + x * b; } return Color.argb(255, (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); }
From source file:Main.java
/** * Returns the complimentary color of the given color * @param color/* w w w. j ava 2s .c o m*/ * @return */ public static int complimentaryColor(int color) { return Color.argb(Color.alpha(color), (~Color.red(color)) & 0xff, (~Color.green(color)) & 0xff, (~Color.blue(color)) & 0xff); }
From source file:Main.java
public static int setColorAlpha(int color, float alpha) { int alpha_int = Math.min(Math.max((int) (alpha * 255.0f), 0), 255); return Color.argb(alpha_int, Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
private static int applyAlpha(final int color, final float alpha) { final int newAlpha = (int) (Color.alpha(color) * alpha); return Color.argb(newAlpha, Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
public static void setGradientForPreferenceView(View v) { int[] colorsForGradient = new int[2]; colorsForGradient[0] = Color.argb(0, 0, 0, 0); colorsForGradient[1] = Color.argb(64, 255, 255, 255); GradientDrawable d = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colorsForGradient); d.setGradientType(GradientDrawable.LINEAR_GRADIENT); d.setShape(GradientDrawable.RECTANGLE); // doesn't help d.setUseLevel(true); d.setDither(true);/* w w w .j a va 2s .c om*/ v.setBackgroundDrawable(d); }
From source file:Main.java
public static int adjustBrightness(int color, float percentage) { return Color.argb(Color.alpha(color), (int) (Color.red(color) * percentage), (int) (Color.green(color) * percentage), (int) (Color.blue(color) * percentage)); }
From source file:Main.java
public static Bitmap doGray(Bitmap src) { final double GS_RED = 0.299; final double GS_GREEN = 0.587; final double GS_BLUE = 0.114; Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); int A, R, G, B, pixel; int w = src.getWidth(); int h = src.getHeight(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { pixel = src.getPixel(x, y);/*from w ww . jav a2 s . c o m*/ A = Color.alpha(pixel); R = Color.red(pixel); G = Color.green(pixel); B = Color.blue(pixel); R = G = B = (int) (GS_RED * R + GS_GREEN * G + GS_BLUE * B); bmOut.setPixel(x, y, Color.argb(A, R, G, B)); } } return bmOut; }
From source file:Main.java
public static int setAlpha(final int color, final int alpha) { final int r = Color.red(color); final int g = Color.green(color); final int b = Color.blue(color); return Color.argb(alpha, r, g, b); }
From source file:Main.java
/** * Method returning color between start and end color proportional to given values. * * @param colorStart start color//ww w . j a va2s . c om * @param colorEnd end color * @param fullValue total value * @param partValue part of fullValue. When partValue equals 0, returning color is colorStart, * when partValue is fullValue returning color is endColor. Otherwise returning * color is from between those, relative to partValue/fullValue ratio. * @return color from between start and end color relative to partValue/fullValue ratio. */ public static int getProportionalColor(int colorStart, int colorEnd, float fullValue, float partValue) { float progress = Math.min(Math.max(partValue, 0f), fullValue) / fullValue; return Color.argb(Math.round(Color.alpha(colorStart) * (1 - progress) + Color.alpha(colorEnd) * progress), Math.round(Color.red(colorStart) * (1 - progress) + Color.red(colorEnd) * progress), Math.round(Color.green(colorStart) * (1 - progress) + Color.green(colorEnd) * progress), Math.round(Color.blue(colorStart) * (1 - progress) + Color.blue(colorEnd) * progress)); }