List of usage examples for android.graphics Bitmap getPixel
@ColorInt public int getPixel(int x, int y)
From source file:Main.java
public static float getValue(Bitmap bitmap, int x, int y) { if (x < 0 || y < 0 || x > (bitmap.getWidth() - 1) || y > (bitmap.getHeight() - 1)) Log.d("GET PIXEL ERROR!!!!!!!!!!!!", "X,Y is " + x + "," + y + "\tmax X,Y is" + bitmap.getWidth() + "," + bitmap.getHeight()); int color = bitmap.getPixel(x, y); int red = Color.red(color); int green = Color.green(color); int blue = Color.blue(color); float intensity = (float) (0.299 * red + 0.587 * green + 0.114 * blue); return intensity; }
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); 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)); }/*from w ww .java 2s. c om*/ } return bmOut; }
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. jav a2 s. co m // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
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 2 s . c o m // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
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)); }/*from w w w. j a v a 2 s . c o m*/ // grayBitmap1.recycle(); // grayBitmap2.recycle(); return result; }
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)); }/*from www .j a va 2s. co m*/ } return bmOut; }
From source file:Main.java
public static int hasColorOnRect(Bitmap src, Rect serchRect, int inputColor) { int width = serchRect.width(); int height = serchRect.height(); if (width == 0 || height == 0) return inputColor; int color = inputColor; if (width == 1 && height == 1) { color = src.getPixel(serchRect.left, serchRect.top); return color != inputColor ? color : inputColor; }// www . ja va2s . c o m if (width == 1 && height > 1) { for (int start = 0; start < height; ++start) { color = src.getPixel(serchRect.left, serchRect.top + start); if (color != inputColor) return color; } return inputColor; } if (width > 1 && height == 1) { for (int start = 0; start < width; ++start) { color = src.getPixel(serchRect.left + start, serchRect.top); if (color != inputColor) return color; } return inputColor; } if (width > 1 && height > 1) { for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { color = src.getPixel(serchRect.left + x, serchRect.top + y); if (color != inputColor) return color; } } return inputColor; } return inputColor; }
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 ww . j a v a 2 s .c o 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
private static List<int[]> getPixels(Bitmap image) { int width = image.getWidth(); int height = image.getHeight(); List<int[]> res = new ArrayList<>(); List<Integer> t = new ArrayList<>(); for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { if (!image.isRecycled()) t.add(image.getPixel(col, row)); }/*from w w w.ja va 2 s .c o m*/ } for (int i = 0; i < t.size(); i += 10) { int[] rr = new int[3]; int argb = t.get(i); rr[0] = (argb >> 16) & 0xFF; rr[1] = (argb >> 8) & 0xFF; rr[2] = (argb) & 0xFF; if (!(rr[0] > 250 && rr[1] > 250 && rr[2] > 250)) { res.add(rr); } } return res; }
From source file:Main.java
@Nullable public static Bitmap removeTransparent(@Nullable Bitmap source) { if (source == null) { return null; }//from w w w. jav a2s .c o m int minX = source.getWidth(); int minY = source.getHeight(); int maxX = -1; int maxY = -1; for (int y = 0; y < source.getHeight(); y++) { for (int x = 0; x < source.getWidth(); x++) { int alpha = (source.getPixel(x, y) >> 24) & 255; if (alpha > 0) { if (x < minX) minX = x; if (x > maxX) maxX = x; if (y < minY) minY = y; if (y > maxY) maxY = y; } } } if ((maxX < minX) || (maxY < minY)) { return null; // Bitmap is entirely transparent } // crop bitmap to non-transparent area and return: return Bitmap.createBitmap(source, minX, minY, (maxX - minX) + 1, (maxY - minY) + 1); }