List of usage examples for android.graphics Color alpha
@IntRange(from = 0, to = 255) public static int alpha(int color)
From source file:Main.java
public static int saturateRelative(int color, float saturationOffset) { float[] hsv = new float[3]; Color.RGBToHSV(Color.red(color), Color.green(color), Color.blue(color), hsv); hsv[1] += saturationOffset;//from w ww.j a v a 2s . c om if (hsv[1] > 1.0f) { hsv[1] = 1.0f; } else if (hsv[1] < 0.0f) { hsv[1] = 0.0f; } return Color.HSVToColor(Color.alpha(color), hsv); }
From source file:Main.java
public static int getMiddleColor(int prevColor, int curColor, float factor) { if (prevColor == curColor) { return curColor; }//from w w w .j a v a2 s .c om ; if (factor == 0f) { return prevColor; } else if (factor == 1f) { return curColor; } int a = getMiddleValue(Color.alpha(prevColor), Color.alpha(curColor), factor); int r = getMiddleValue(Color.red(prevColor), Color.red(curColor), factor); int g = getMiddleValue(Color.green(prevColor), Color.green(curColor), factor); int b = getMiddleValue(Color.blue(prevColor), Color.blue(curColor), factor); return Color.argb(a, r, g, b); }
From source file:Main.java
public static int lighter(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); }
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 w w w .j av a 2 s .co m } }
From source file:Main.java
public static Bitmap doColorFilter(Bitmap src, double red, double green, double blue) { int w = src.getWidth(); int h = src.getHeight(); Bitmap bmOut = Bitmap.createBitmap(w, h, src.getConfig()); int A, R, G, B, pixel; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { pixel = src.getPixel(x, y);/*from ww w .ja va 2 s. c o m*/ A = Color.alpha(pixel); R = (int) (Color.red(pixel) * red); G = (int) (Color.green(pixel) * green); B = (int) (Color.blue(pixel) * blue); bmOut.setPixel(x, y, Color.argb(A, R, G, B)); } } return bmOut; }
From source file:Main.java
public static Bitmap doInvert(Bitmap src) { Bitmap bmOut = Bitmap.createBitmap(src.getWidth(), src.getHeight(), src.getConfig()); int A, R, G, B; int pixelColor; int w = src.getWidth(); int h = src.getHeight(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { pixelColor = src.getPixel(x, y); A = Color.alpha(pixelColor); R = 255 - Color.red(pixelColor); G = 255 - Color.green(pixelColor); B = 255 - Color.blue(pixelColor); bmOut.setPixel(x, y, Color.argb(A, R, G, B)); }/* ww w . j a v a 2s . c o m*/ } return bmOut; }
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;// w w w . j a va 2s . co 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
/** * Method returning given color modified to lighter color (positive translation) or darker * (negative translation).//from ww w.j a va 2 s . co m * * @param primaryColor basic color * @param translation positive or negative value of color translation * @return lighter/darker color */ public static int getColorWithTranslateBrightness(int primaryColor, int translation) { if (translation >= 0) { return Color.argb(Color.alpha(primaryColor), Math.min(Color.red(primaryColor) + translation, 255), Math.min(Color.green(primaryColor) + translation, 255), Math.min(Color.blue(primaryColor) + translation, 255)); } else { return Color.argb(Color.alpha(primaryColor), Math.max(Color.red(primaryColor) + translation, 0), Math.max(Color.green(primaryColor) + translation, 0), Math.max(Color.blue(primaryColor) + translation, 0)); } }
From source file:Main.java
private static int adjustColorBrightness(int argb, float factor) { final float[] hsv = new float[3]; Color.colorToHSV(argb, hsv);//from w w w . j a v a 2s. c o m hsv[2] = Math.min(hsv[2] * factor, 1f); return Color.HSVToColor(Color.alpha(argb), hsv); }
From source file:Main.java
public static int mixColors(int fromColor, int toColor, float ratio) { int fromRed = Color.red(fromColor); int toRed = Color.red(toColor); int diffRed = toRed - fromRed; int fromGreen = Color.green(fromColor); int toGreen = Color.green(toColor); int diffGreen = toGreen - fromGreen; int fromBlue = Color.blue(fromColor); int toBlue = Color.blue(toColor); int diffBlue = toBlue - fromBlue; int fromAlpha = Color.alpha(fromColor); int toAlpha = Color.alpha(toColor); int diffAlpha = toAlpha - fromAlpha; return Color.argb((int) (fromAlpha + diffAlpha * ratio), (int) (fromRed + diffRed * ratio), (int) (fromGreen + diffGreen * ratio), (int) (fromBlue + diffBlue * ratio)); }