List of usage examples for android.graphics Bitmap getPixel
@ColorInt public int getPixel(int x, int y)
From source file:Main.java
/** * Returns true if we should add padding to this icon. We use a heuristic that if the pixels in * all four corners of the icon are not transparent, we assume the icon is square and maximally * sized, i.e. in need of padding. Otherwise, no padding is added. *///from w w w . j ava 2 s . c om private static boolean shouldPadIcon(Bitmap icon) { int maxX = icon.getWidth() - 1; int maxY = icon.getHeight() - 1; if ((Color.alpha(icon.getPixel(0, 0)) != 0) && (Color.alpha(icon.getPixel(maxX, maxY)) != 0) && (Color.alpha(icon.getPixel(0, maxY)) != 0) && (Color.alpha(icon.getPixel(maxX, 0)) != 0)) { return true; } return false; }
From source file:Main.java
public static double getPixel(int x, int y, Bitmap bitmap) { if (x < 0 || x >= bitmap.getWidth() || y < 0 || y >= bitmap.getHeight()) return 0; return bitmap.getPixel(x, y); }
From source file:Main.java
public static boolean hasTransparentCorners(Bitmap bitmap) { int width = bitmap.getWidth() - 1; int height = bitmap.getHeight() - 1; return bitmap.getPixel(0, 0) == Color.TRANSPARENT || bitmap.getPixel(width, 0) == Color.TRANSPARENT || bitmap.getPixel(0, height) == Color.TRANSPARENT || bitmap.getPixel(width, height) == Color.TRANSPARENT; }
From source file:Main.java
public static boolean hasTransparentCorners(@NonNull Bitmap bitmap) { int right = bitmap.getWidth() - 1; int bottom = bitmap.getHeight() - 1; return bitmap.getPixel(0, 0) == Color.TRANSPARENT || bitmap.getPixel(right, 0) == Color.TRANSPARENT || bitmap.getPixel(0, bottom) == Color.TRANSPARENT || bitmap.getPixel(right, bottom) == Color.TRANSPARENT; }
From source file:Main.java
public static int colorDrawableGetColor(ColorDrawable d) { try {//from w ww . j a v a 2 s . c om Method getColor = d.getClass().getMethod("getColor"); return (Integer) getColor.invoke(d); } catch (NoSuchMethodException ignore) { } catch (InvocationTargetException ignore) { } catch (IllegalAccessException ignore) { } catch (ClassCastException ignore) { } // For some reason the following doesn't work on Android 15, but the above does, and the below // works for Android <= 10, so the function as a whole works but is a dirty hack. Bitmap b = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); d.draw(new Canvas(b)); return b.getPixel(0, 0); }
From source file:Main.java
/** * Fill the hole in the image (version 2) *//* w ww . j a va 2 s .c o m*/ public static void fillHole2(Bitmap bmp) { for (int j = 1; j < bmp.getWidth(); j++) { for (int i = 1; i < bmp.getHeight() - 1; i++) { if ((bmp.getPixel(i, j) == Color.TRANSPARENT) && (bmp.getPixel(i + 1, j) != Color.TRANSPARENT)) { bmp.setPixel(i, j, bmp.getPixel(i + 1, j)); // set to the next-below pixel } } } }
From source file:Main.java
/** * Fill the hole in the image (version 1) *///from w ww . j a va 2 s .c o m public static void fillHole1(Bitmap bmp) { for (int j = 1; j < bmp.getWidth() - 1; j++) { for (int i = 1; i < bmp.getHeight(); i++) { if ((bmp.getPixel(i, j) == Color.TRANSPARENT) && (bmp.getPixel(i, j + 1) != Color.TRANSPARENT)) { bmp.setPixel(i, j, bmp.getPixel(i, j + 1)); // set to the right-next pixel } } } }
From source file:Main.java
private static float[] getMainHSV(Bitmap bm) { Bitmap onePixelBitmap = Bitmap.createScaledBitmap(bm, 1, 1, true); int pixel = onePixelBitmap.getPixel(0, 0); int red = Color.red(pixel); int blue = Color.blue(pixel); int green = Color.green(pixel); float[] hsvVals = new float[3]; Color.RGBToHSV(red, green, blue, hsvVals); return hsvVals; }
From source file:Main.java
public static int getHighlightColorFromBackground(final Activity activity) { int incolor = Color.BLACK; final Bitmap screenshot1px = getScaledScreenshot(activity, 1, 1, false); if (null != screenshot1px) { incolor = screenshot1px.getPixel(0, 0); }//from w w w. j av a2 s .c om return getHighlightColor(incolor); }
From source file:Main.java
public static Bitmap cropBorders(Bitmap bitmap, int width, int height) { int top = 0;// ww w. j a v a 2 s. c om for (int i = 0; i < height / 2; i++) { int pixel1 = bitmap.getPixel(width / 2, i); int pixel2 = bitmap.getPixel(width / 2, height - i - 1); if ((pixel1 == 0 || pixel1 == -16777216) && (pixel2 == 0 || pixel2 == -16777216)) { top = i; } else { break; } } int left = 0; for (int i = 0; i < width / 2; i++) { int pixel1 = bitmap.getPixel(i, height / 2); int pixel2 = bitmap.getPixel(width - i - 1, height / 2); if ((pixel1 == 0 || pixel1 == -16777216) && (pixel2 == 0 || pixel2 == -16777216)) { left = i; } else { break; } } if (left >= width / 2 - 10 || top >= height / 2 - 10) return bitmap; // Cut off the transparency on the borders return Bitmap.createBitmap(bitmap, left, top, (width - (2 * left)), (height - (2 * top))); }