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 Bitmap subtract(Bitmap bitmap1, Bitmap bitmap2) { int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); int resultValue = Math.abs(value2 - value1); // resultValue = (resultValue>255/3)?resultValue:0; result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); }/*from ww w.j a v a 2 s. c om*/ // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
From source file:Main.java
public static Bitmap effectWhiten(Bitmap bitmap, int threshold) { if (bitmap == null) { return bitmap; }//w ww. j av a 2 s. co m Bitmap dst = bitmap.copy(Bitmap.Config.ARGB_8888, true); int height = dst.getHeight(); int width = dst.getWidth(); int[] pixels = new int[(width * height)]; dst.getPixels(pixels, 0, width, 0, 0, width, height); for (int YY = 0; YY < width; ++YY) { for (int XX = 0; XX < height; ++XX) { int bitmapColor = pixels[(YY + XX * width)]; int[] color = { Color.red(bitmapColor), Color.green(bitmapColor), Color.blue(bitmapColor) }; if (color[0] > threshold && color[1] > threshold && color[2] > threshold) { color[0] = 255; color[1] = 255; color[2] = 255; } pixels[(YY + XX * width)] = Color.rgb(color[0], color[1], color[2]); } } dst.setPixels(pixels, 0, width, 0, 0, width, height); return dst; }
From source file:Main.java
public static Bitmap multiply(Bitmap bitmap1, Bitmap bitmap2) { double alpha = 0.1; int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); int resultValue = (int) (Math.abs((value2 / 255.0) * (value1 / 255.0)) * 255); // resultValue = (resultValue>255/2)?255:0; result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); }// ww w .j a va 2s . c o m // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
From source file:Main.java
public static int getGradientColor(int startColor, int endColor, int incrementStep, int i) { int r = interpolate(Color.red(startColor), Color.red(endColor), incrementStep, i), g = interpolate(Color.green(startColor), Color.green(endColor), incrementStep, i), b = interpolate(Color.blue(startColor), Color.blue(endColor), incrementStep, i); return Color.rgb(r, g, b); }
From source file:Main.java
private static int getGradientColor(int startColor, int endColor, int incrementStep, int i) { int r = interpolate(Color.red(startColor), Color.red(endColor), incrementStep, i), g = interpolate(Color.green(startColor), Color.green(endColor), incrementStep, i), b = interpolate(Color.blue(startColor), Color.blue(endColor), incrementStep, i); return Color.rgb(r, g, b); }
From source file:Main.java
/** * Convert rgb string color to color/*from w w w .ja v a 2 s . c o m*/ * * @param rgb The rgb string representation of the color * @return An Integer color value */ public static Integer getColorFromRgb(@NonNull String rgb) { String[] rgbArray = rgb.split("\\s+"); return Color.rgb(Integer.parseInt(rgbArray[0]), Integer.parseInt(rgbArray[1]), Integer.parseInt(rgbArray[2])); }
From source file:Main.java
public static int darker(int color) { int r = Color.red(color); int b = Color.blue(color); int g = Color.green(color); return Color.rgb((int) (r * .9), (int) (g * .9), (int) (b * .9)); }
From source file:Main.java
public static Bitmap divide(Bitmap bitmap1, Bitmap bitmap2) { double alpha = Double.MIN_VALUE; int width = bitmap1.getWidth(); int height = bitmap1.getHeight(); Bitmap grayBitmap1 = toGrayScale(bitmap1); Bitmap grayBitmap2 = toGrayScale(bitmap2); Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); for (int x = 0; x < width; x++) for (int y = 0; y < height; y++) { int value1 = Color.blue(grayBitmap1.getPixel(x, y)); int value2 = Color.blue(grayBitmap2.getPixel(x, y)); // int resultValue = (int) (Math.abs((Math.log((value1 + alpha)/(value2 + alpha))) * 1000)); int resultValue = (int) ((Math.abs(Math.log((value1 + alpha) / (value2 + alpha)))) * 255); result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue)); }/*www . j a va 2s . c o m*/ // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
From source file:Main.java
private static int getColorWithOverlay(int baseColor, int overlayColor, float overlayAlpha) { return Color.rgb( (int) (overlayAlpha * Color.red(baseColor) + (1f - overlayAlpha) * Color.red(overlayColor)), (int) (overlayAlpha * Color.green(baseColor) + (1f - overlayAlpha) * Color.green(overlayColor)), (int) (overlayAlpha * Color.blue(baseColor) + (1f - overlayAlpha) * Color.blue(overlayColor))); }
From source file:Main.java
public static Bitmap drawTextToBitmap(Context gContext, int gResId, String gText) { Resources resources = gContext.getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); Bitmap.Config bitmapConfig = bitmap.getConfig(); // set default bitmap config if none if (bitmapConfig == null) { bitmapConfig = Bitmap.Config.ARGB_8888; }/* w w w. j a v a 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 - #808080 paint.setColor(Color.rgb(127, 127, 127)); // text size in pixels paint.setTextSize((int) (14 * scale * 5)); // text shadow paint.setShadowLayer(1f, 0f, 1f, Color.WHITE); // draw text to the Canvas center Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); // int x = (bitmap.getWidth() - bounds.width()) / 2; // int y = (bitmap.getHeight() + bounds.height()) / 2; //draw text to the bottom int x = (bitmap.getWidth() - bounds.width()) / 10 * 9; int y = (bitmap.getHeight() + bounds.height()) / 10 * 9; canvas.drawText(gText, x, y, paint); return bitmap; }