List of usage examples for android.graphics Color rgb
@ColorInt public static int rgb(float red, float green, float blue)
From source file:Main.java
public static int getTintedBackgroundColor() { final int c = getCurrentHourColor(); final int red = Color.red(c) + (int) (TINTED_LEVEL * (255 - Color.red(c))); final int green = Color.green(c) + (int) (TINTED_LEVEL * (255 - Color.green(c))); final int blue = Color.blue(c) + (int) (TINTED_LEVEL * (255 - Color.blue(c))); return Color.rgb(red, green, blue); }
From source file:Main.java
/** * @param bitmap Bitmap that will be processed * @return The average color of the input bitmap *///w w w.ja v a 2 s.c o m public static int getAverageColor(Bitmap bitmap) { if (bitmap == null) { Log.e("getAverageColor()", "ERROR: No bitmap generated to get average colour from."); return Color.BLACK; } int redBucket = 0; int greenBucket = 0; int blueBucket = 0; int width = bitmap.getWidth(); int height = bitmap.getHeight(); int pixelCount = 0; int c = 0; for (int y = 0; y < height; y += STEP_SIZE_PIXEL) { for (int x = 0; x < width; x += STEP_SIZE_PIXEL) { c = bitmap.getPixel(x, y); redBucket += Color.red(c); greenBucket += Color.green(c); blueBucket += Color.blue(c); pixelCount++; } redBucket += Color.red(c); } return Color.rgb(redBucket / pixelCount, greenBucket / pixelCount, blueBucket / pixelCount); }
From source file:Main.java
/** * @param x X coordinate of the region/* w w w .j av a 2s . c o m*/ * @param y Y coordinate of the region * @param bmp Source bitmap * @return color value of the region * */ static int computeAverageColor(int x, int y, Bitmap bmp) { int res[] = new int[3]; for (int col = 0; col < 3; col++) { for (int i = x * STEP; i < (x + 1) * STEP; i++) for (int j = y * STEP; j < (y + 1) * STEP; j++) { switch (col) { case 0: //red res[0] = res[0] + Color.red(bmp.getPixel(i, j)); break; case 1: //green res[1] = res[1] + Color.green(bmp.getPixel(i, j)); break; case 2: //blue res[2] = res[2] + Color.blue(bmp.getPixel(i, j)); break; } } res[col] = res[col] / (STEP * STEP); } return Color.rgb(res[0], res[1], res[2]); }
From source file:Main.java
public static Bitmap drawTextToBitmap(Bitmap bitmap, String gText) { //Resources resources = gContext.getResources(); //float scale = resources.getDisplayMetrics().density; android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }//from w w w. ja va 2 s. co m // resource bitmaps are imutable, // so we need to convert it to mutable one bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); // new antialised Paint Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); // text color - #3D3D3D paint.setColor(Color.rgb(61, 61, 61)); // text size in pixels paint.setTextSize((int) (21)); //* scale)); // text shadow paint.setShadowLayer(2f, 1f, 1f, Color.WHITE); // draw text to the Canvas center //Rect bounds = new Rect(); //paint.getTextBounds(gText, 0, gText.length(), bounds); int x = bitmap.getWidth() - 150;//bounds.width()) - 150; int y = bitmap.getHeight() - 27;//bounds.height()) - 30; // fill canvas.drawRect(x, y, x + 150, y + 27, paint); canvas.drawText(gText, x, y + 20, paint); return bitmap; }
From source file:Main.java
/** * This method calculates a combination of colors using an opacity of the foreground layered * over the background color. This allows us to optimize color calculations instead of setting * alpha values in the color attributes on the views directly. * * @param opacity A value in the range of 0 to 1 that indicates the opacity desired for the * overlay color// w ww .j a v a2 s . c o m * @param overlayColor The foreground color that the opacity will be applied to * @param primaryColor The background color that the foreground color is applied to * @return The combined color value */ static int calculateOpacityTransform(final double opacity, final int overlayColor, final int primaryColor) { final int redPrimary = Color.red(primaryColor); final int redOverlay = Color.red(overlayColor); final int greenPrimary = Color.green(primaryColor); final int greenOverlay = Color.green(overlayColor); final int bluePrimary = Color.blue(primaryColor); final int blueOverlay = Color.blue(overlayColor); final int redCalculated = (int) ((1 - opacity) * redPrimary + opacity * redOverlay); final int greenCalculated = (int) ((1 - opacity) * greenPrimary + opacity * greenOverlay); final int blueCalculated = (int) ((1 - opacity) * bluePrimary + opacity * blueOverlay); return Color.rgb(redCalculated, greenCalculated, blueCalculated); }
From source file:Main.java
/** * @return/*from w ww .java2 s.com*/ */ private static Map<Integer, Integer> initNumberToColorMap() { HashMap<Integer, Integer> localMap = new HashMap<Integer, Integer>(); int r = LOW; int g = LOW; int b = HALF; // factor (increment or decrement) int rF = 0; int gF = 0; int bF = 1; int count = 0; // 1276 steps while (true) { localMap.put(count++, Color.rgb(r, g, b)); if (b == HIGH) { gF = 1; // increment green } if (g == HIGH) { bF = -1; // decrement blue // rF = +1; // increment red } if (b == LOW) { rF = +1; // increment red } if (r == HIGH) { gF = -1; // decrement green } if (g == LOW && b == LOW) { rF = -1; // decrement red } if (r < HALF && g == LOW && b == LOW) { break; // finish } r += rF; g += gF; b += bF; r = rangeCheck(r); g = rangeCheck(g); b = rangeCheck(b); } initList(localMap); return localMap; }
From source file:com.ahamed.sample.common.decorator.ArticleItemDecorator.java
public ArticleItemDecorator() { myPaint.setColor(Color.rgb(240, 240, 240)); }
From source file:com.game.prayansh.ultimatetictactoe.ui.ThemeManager.java
public static void setDC(Context context) { int seed = (int) (Math.random() * 10); theme = new Theme(0, R.drawable.black_background, (seed > 5) ? R.drawable.batman : R.drawable.superman, (seed <= 5) ? R.drawable.batman : R.drawable.superman, ContextCompat.getColor(context, R.color.white), R.drawable.blank_black, R.drawable.blank_black_highlight, Color.rgb(255, 255, 255), R.drawable.btn_dark); }
From source file:com.midisheetmusic.RecentSongsActivity.java
@Override public void onCreate(Bundle state) { super.onCreate(state); setTitle("MidiSheetMusic: Recent Songs"); getListView().setBackgroundColor(Color.rgb(0, 0, 0)); // Load the list of songs loadFileList();/*from w w w .jav a2 s. c o m*/ adapter = new IconArrayAdapter<FileUri>(this, android.R.layout.simple_list_item_1, filelist); this.setListAdapter(adapter); }
From source file:Main.java
private static int perferBlue(int color) { final int delta = 20; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); if (b > 255 - delta) { r -= delta;/* w w w . j ava2 s . c o m*/ r = (int) clamp(r, 0, 255); g -= delta; g = (int) clamp(g, 0, 255); } else { b += delta; } return Color.rgb(r, g, b); }