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 getColor(String colorHex) { if (!colorHex.startsWith("#")) colorHex = "#" + colorHex; int a;//from w w w. j a v a 2 s . c o m int r; int g; int b; if (colorHex.length() == 7) { a = 0xFF; r = Integer.parseInt(colorHex.substring(1, 3), 16); g = Integer.parseInt(colorHex.substring(3, 5), 16); b = Integer.parseInt(colorHex.substring(5, 7), 16); } else if (colorHex.length() == 9) { a = Integer.parseInt(colorHex.substring(1, 3), 16); r = Integer.parseInt(colorHex.substring(3, 5), 16); g = Integer.parseInt(colorHex.substring(5, 7), 16); b = Integer.parseInt(colorHex.substring(7, 9), 16); } else return Color.BLACK; int c = Color.argb(a, r, g, b); return c; }
From source file:Main.java
public static int setAlpha(int color, float newAlpha) { int intAlpha = (int) (newAlpha * 255); return Color.argb(intAlpha, Color.red(color), Color.green(color), Color.blue(color)); }
From source file:Main.java
public static void drawRuleOfThird(Canvas canvas, RectF bounds) { Paint p = new Paint(); p.setStyle(Paint.Style.STROKE); p.setColor(Color.argb(128, 255, 255, 255)); p.setStrokeWidth(2);/*from w w w .ja v a 2s . c o m*/ float stepX = bounds.width() / 3.0f; float stepY = bounds.height() / 3.0f; float x = bounds.left + stepX; float y = bounds.top + stepY; for (int i = 0; i < 2; i++) { canvas.drawLine(x, bounds.top, x, bounds.bottom, p); x += stepX; } for (int j = 0; j < 2; j++) { canvas.drawLine(bounds.left, y, bounds.right, y, p); y += stepY; } }
From source file:Main.java
private static View createTranslucentStatusBarView(Activity activity, int alpha) { View statusBarView = new View(activity); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); statusBarView.setLayoutParams(params); statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0)); return statusBarView; }
From source file:Main.java
/** * Retuns a darker color from a specified color by the factor. * @param color/* w w w . ja v a2 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
/** * Adjust the alpha of a color.// w ww. ja va2 s . c om * @param color the color [0x00000000, 0xffffffff] * @param factor the factor for the alpha [0,1] * @return the adjusted color */ public static int adjustAlpha(int color, float factor) { int alpha = Math.round(Color.alpha(color) * factor); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); return Color.argb(alpha, red, green, blue); }
From source file:Main.java
/** * Concerts a String color (#ff882465) to an int color * * @throws NumberFormatException//from ww w .j av a2 s . c o m */ public static int convertToColorInt(String a, String r, String g, String b, boolean useAlpha) { int alpha = useAlpha ? Integer.parseInt(a, 16) : 0xff; int red = Integer.parseInt(r, 16); int green = Integer.parseInt(g, 16); int blue = Integer.parseInt(b, 16); return Color.argb(useAlpha ? alpha : -1, red, green, blue); }
From source file:Main.java
public static int scaleColor(int color, float factor, boolean scaleAlpha) { return Color.argb(scaleAlpha ? (Math.round(Color.alpha(color) * factor)) : Color.alpha(color), Math.round(Color.red(color) * factor), Math.round(Color.green(color) * factor), Math.round(Color.blue(color) * factor)); }
From source file:Main.java
public static int getDominantColor(Bitmap bitmap) { if (null == bitmap) return Color.TRANSPARENT; int redBucket = 0; int greenBucket = 0; int blueBucket = 0; int alphaBucket = 0; boolean hasAlpha = bitmap.hasAlpha(); int pixelCount = bitmap.getWidth() * bitmap.getHeight(); int[] pixels = new int[pixelCount]; bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); for (int y = 0, h = bitmap.getHeight(); y < h; y++) { for (int x = 0, w = bitmap.getWidth(); x < w; x++) { int color = pixels[x + y * w]; // x + y * barHeight redBucket += (color >> 16) & 0xFF; // Color.red greenBucket += (color >> 8) & 0xFF; // Color.greed blueBucket += (color & 0xFF); // Color.blue if (hasAlpha) alphaBucket += (color >>> 24); // Color.alpha }// ww w . j a v a 2 s. c o m } return Color.argb((hasAlpha) ? (alphaBucket / pixelCount) : 255, redBucket / pixelCount, greenBucket / pixelCount, blueBucket / pixelCount); }
From source file:Main.java
public static Bitmap handleImageOldPhoto(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); int color;// w w w.j a v a2 s. 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 = (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; } if (g > 255) { g = 255; } if (b > 255) { b = 255; } newPx[i] = Color.argb(a, r, g, b); } bmp.setPixels(newPx, 0, width, 0, 0, width, height); return bmp; }