List of usage examples for android.graphics Bitmap getWidth
public final int getWidth()
From source file:Main.java
public static Bitmap compoundBitmap(Bitmap bg, Bitmap fg, int left, int top) { Bitmap result = Bitmap.createBitmap(bg.getWidth(), bg.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); canvas.drawBitmap(bg, 0, 0, null);//w ww . j a v a 2 s . c o m canvas.drawBitmap(fg, left, top, null); return result; }
From source file:Main.java
/** * Method to remove colors in a Bitmap, creating a gray scale image. * * @param source The original Bitmap./*w w w .jav a 2 s .c o m*/ * @return The gray scale Bitmap. */ public static Bitmap toGrayscale(Bitmap source) { Bitmap bmpGrayscale = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmpGrayscale); canvas.drawBitmap(source, 0, 0, getGrayScalePaint()); return bmpGrayscale; }
From source file:Main.java
public static int getBitmapWidth(String path, String fileName) { Bitmap bitmap = BitmapFactory.decodeFile(path + fileName); return bitmap == null ? 0 : bitmap.getWidth(); }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap blur(Context context, Bitmap image) { int width = Math.round(image.getWidth() * BITMAP_SCALE); int height = Math.round(image.getHeight() * BITMAP_SCALE); Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); RenderScript rs = RenderScript.create(context); ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); theIntrinsic.setRadius(BLUR_RADIUS); theIntrinsic.setInput(tmpIn);// w w w . j a v a 2 s .co m theIntrinsic.forEach(tmpOut); tmpOut.copyTo(outputBitmap); return outputBitmap; }
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)); }// w w w . j a v a2s. 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
public static int[] extractPixels(final Bitmap bitmap) { final int w = bitmap.getWidth(); final int h = bitmap.getHeight(); final int[] colors = new int[w * h]; bitmap.getPixels(colors, 0, w, 0, 0, w, h); return colors; }
From source file:Main.java
public static Bitmap scaleBitmap(Bitmap bitmap, float scale) { int width = (int) ((float) bitmap.getWidth() * scale); int height = (int) ((float) bitmap.getHeight() * scale); if (bitmap.getWidth() != width || bitmap.getHeight() != height) { return Bitmap.createScaledBitmap(bitmap, width, height, true /* filter */); } else {/*from w ww . j av a 2s . com*/ return bitmap; } }
From source file:Main.java
public static Bitmap createScaledBitmap(String path, float scale, boolean filtering) { Bitmap src = BitmapFactory.decodeFile(path); int width = (int) (src.getWidth() * scale + 0.5f); int height = (int) (src.getHeight() * scale + 0.5f); return Bitmap.createScaledBitmap(src, width, height, filtering); }
From source file:Main.java
public static float getScale(Bitmap bitmap, Context context) { int bitmapWidth = bitmap.getWidth(); int bitmapHeight = bitmap.getHeight(); DisplayMetrics outMetrics = getScreenPixels(context); int displayW = outMetrics.widthPixels; int displayH = outMetrics.heightPixels; float scale = bitmapHeight > bitmapWidth ? displayH / (bitmapHeight * 1f) : displayW / (bitmapWidth * 1f); return scale; }
From source file:Main.java
/** * Find the difference between two bitmaps using average of per-pixel differences. * * @param a first {@link android.graphics.Bitmap}. * @param b second {@link android.graphics.Bitmap}. * @return the difference.// www .ja va2 s . c o m */ public static double calcDifferenceMetric(Bitmap a, Bitmap b) { if (a.getWidth() != b.getWidth() || a.getHeight() != b.getHeight()) { throw new IllegalArgumentException("Bitmap dimensions for arguments do not match a=" + a.getWidth() + "x" + a.getHeight() + ", b=" + b.getWidth() + "x" + b.getHeight()); } // TODO: Optimize this in renderscript to avoid copy. int[] aPixels = new int[a.getHeight() * a.getWidth()]; int[] bPixels = new int[aPixels.length]; a.getPixels(aPixels, /*offset*/0, /*stride*/a.getWidth(), /*x*/ 0, /*y*/0, a.getWidth(), a.getHeight()); b.getPixels(bPixels, /*offset*/0, /*stride*/b.getWidth(), /*x*/ 0, /*y*/0, b.getWidth(), b.getHeight()); double diff = 0; for (int i = 0; i < aPixels.length; i++) { int aPix = aPixels[i]; int bPix = bPixels[i]; diff += Math.abs(Color.red(aPix) - Color.red(bPix)); // red diff += Math.abs(Color.green(aPix) - Color.green(bPix)); // green diff += Math.abs(Color.blue(aPix) - Color.blue(bPix)); // blue } diff /= (aPixels.length * 3); return diff; }