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
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 String[] convertToARGB(int color) { String alpha = Integer.toHexString(Color.alpha(color)).toUpperCase(Locale.getDefault()); String red = Integer.toHexString(Color.red(color)).toUpperCase(Locale.getDefault()); String green = Integer.toHexString(Color.green(color)).toUpperCase(Locale.getDefault()); String blue = Integer.toHexString(Color.blue(color)).toUpperCase(Locale.getDefault()); // we want the strings with a leading 0 if needed return new String[] { ("00" + alpha).substring(alpha.length()), ("00" + red).substring(red.length()), ("00" + green).substring(green.length()), ("00" + blue).substring(blue.length()) }; }
From source file:Main.java
public static Bitmap olderImage(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;//from ww w .j a v a2 s .c om 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 = (int) (0.393 * r + 0.769 * g + 0.189 * b); g = (int) (0.349 * r + 0.686 * g + 0.168 * b); b = (int) (0.272 * r + 0.534 * g + 0.131 * 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
public static Bitmap backsheetImage(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;/* w w w . j av a 2 s.c o m*/ 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
/** * Returns the complimentary color of the given color * @param color/*from ww w. j a v a2s. 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 Bitmap reliefImage(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;// w w w . j av a 2 s.c om 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 = 1; i < oldPx.length; i++) { color = oldPx[i - 1]; r = Color.red(color); g = Color.green(color); b = Color.blue(color); a = Color.alpha(color); int nextColor = oldPx[i]; int r1 = Color.red(nextColor); int g1 = Color.green(nextColor); int b1 = Color.blue(nextColor); r = r1 - r + 127; g = g1 - g + 127; b = b1 - b + 127; 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
/** * Retuns a darker color from a specified color by the factor. * @param color/* w w w .jav a 2 s. c o m*/ * @param factor * @return */ public static int darker(int color, float factor) { int a = Color.alpha(color); int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0), Math.max((int) (b * factor), 0)); }
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
private static int modulateColorAlpha(int baseColor, float alphaMod) { if (alphaMod == 1.0f) { return baseColor; }// www .j a va2s . co m final int baseAlpha = Color.alpha(baseColor); final int alpha = constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255); return (baseColor & 0xFFFFFF) | (alpha << 24); }
From source file:Main.java
public static void smoothToTransparentFromColor(final View view, final int color) { Date firstDate = new Date(); final long firstTime = firstDate.getTime(); executeAsyncTask(new AsyncTask<Void, Integer, Void>() { int n = 1, t = 4000; boolean increaseN; @Override/*from w w w. j ava 2s . c o m*/ protected Void doInBackground(Void... params) { while (!isCancelled()) { Date currentDate = new Date(); long diffTime = currentDate.getTime() - firstTime; double y = getCosY(diffTime); int alpha = (int) (y * Color.alpha(color)); int resultColor = setAlphaComponent(color, alpha); if (alpha < 0.038 * 255) { publishProgress(0); this.cancel(true); return null; } publishProgress(resultColor, alpha); try { Thread.sleep(38); } catch (InterruptedException e) { e.printStackTrace(); } } return null; } @Override protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); view.setBackgroundColor(values[0]); } }); }