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 interpolate(int c1, int c2, float f) { int alpha = (int) ((Color.alpha(c2) - Color.alpha(c1)) * f) + Color.alpha(c1); int red = (int) ((Color.red(c2) - Color.red(c1)) * f) + Color.red(c1); int green = (int) ((Color.green(c2) - Color.green(c1)) * f) + Color.green(c1); int blue = (int) ((Color.blue(c2) - Color.blue(c1)) * f) + Color.blue(c1); //Log.v("ColorHelper","alpha = "+alpha); return Color.argb(alpha, red, green, blue); }
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
/** * Alters the alpha of a given color and spits out the new color. * @param color the color to change the alpha of. * @param value the new value of the alpha field. * @return the new color with the new alpha level. *///from w ww .j a va2 s .c o m public static int getNewColorAlpha(int color, float value) { int alpha = Math.round(Color.alpha(color) * value); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return Color.argb(alpha, r, g, b); }
From source file:Main.java
public static void addTouchFeedback(final ImageView view) { view.setOnTouchListener(new View.OnTouchListener() { private Rect rect; @Override//from www . j ava 2 s . c o m public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { view.setColorFilter(Color.argb(50, 0, 0, 0)); rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); } if (event.getAction() == MotionEvent.ACTION_UP) { view.setColorFilter(Color.argb(0, 0, 0, 0)); } if (event.getAction() == MotionEvent.ACTION_MOVE) { if (!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())) { view.setColorFilter(Color.argb(0, 0, 0, 0)); } } return false; } }); }
From source file:Main.java
public static int transformIfTooWhite(int color) { int alpha = Color.alpha(color); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); float whiteRatio = (red + green + blue) / 3f / 255f * (alpha / 255f); float transformRatio = 0.7f; if (whiteRatio > transformRatio) { red *= transformRatio;/*from w ww .j a v a 2 s . c o m*/ green *= transformRatio; blue *= transformRatio; color = Color.argb(alpha, red, green, blue); } return color; }
From source file:Main.java
/** * Method returning color with modified alpha proportional to given values. * * @param color color to modify//from ww w. j av a 2 s . com * @param fullValue total value * @param partValue part of fullValue. When partValue equals fullValue, the alpha is 255. * @return color with alpha relative to partValue/fullValue ratio. */ public static int getColorWithProportionalAlpha(int color, float fullValue, float partValue) { float progress = Math.min(Math.max(partValue, 0), fullValue) / fullValue; return Color.argb(Math.round(Color.alpha(color) * progress), Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
/** * Returns a color based that is ratio% of color1 and (1 - ratio)% of color2 (including alpha). *///ww w .ja v a 2 s . c o m private static int blendColors(int color1, int color2, double ratio) { double ir = 1.0 - ratio; int a = (int) (Color.alpha(color1) * ratio + Color.alpha(color2) * ir); int r = (int) (Color.red(color1) * ratio + Color.red(color2) * ir); int g = (int) (Color.green(color1) * ratio + Color.green(color2) * ir); int b = (int) (Color.blue(color1) * ratio + Color.blue(color2) * ir); return Color.argb(a, r, g, b); }
From source file:Main.java
public static void invertImage(Bitmap b) { int A, R, G, B; int pixelColor; int height = b.getHeight(); int width = b.getWidth(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { pixelColor = b.getPixel(x, y); A = Color.alpha(pixelColor); R = 255 - Color.red(pixelColor); G = 255 - Color.green(pixelColor); B = 255 - Color.blue(pixelColor); b.setPixel(x, y, Color.argb(A, R, G, B)); }//from ww w. ja v a 2 s . c om } }
From source file:Main.java
/** * Composite two potentially translucent colors over each other and returns the result. *///from w w w . j a v a2s . c o m 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
/** * Alters the alpha of the given color without multiplying the current value. * The current alpha value is replaced by the new one. See {#getNewColorAlpha} to see * how to get a new alpha color by multiplying the current value by the new value. * @param color the color to alter./*from w ww . j a v a 2 s .c o m*/ * @param value the new alpha value. * @return the new color. */ public static int getNewColorAlphaNoMult(int color, float value) { int alpha = Math.round(value); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return Color.argb(alpha, r, g, b); }