List of usage examples for android.graphics Bitmap getHeight
public final int getHeight()
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, int width, int height) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) width / w); float scaleHeight = ((float) height / h); matrix.postScale(scaleWidth, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true); return newbmp; }
From source file:Main.java
public static Bitmap effectWhiten(Bitmap bitmap, int threshold) { if (bitmap == null) { return bitmap; }/* ww w .j a v a2 s .com*/ 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 getBitmap(int background, Bitmap contour, float alpha) { Bitmap bitmap = Bitmap.createBitmap(contour.getWidth(), contour.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawColor(background);//from w w w.j ava 2s . co m return getBitmap(bitmap, contour, alpha); }
From source file:Main.java
public static Bitmap circleBitmap(final Bitmap source) { int width = source.getWidth(); int height = source.getHeight(); Paint paint = new Paint(); paint.setAntiAlias(true);// w ww . ja va 2 s. co m paint.setColor(Color.WHITE); Bitmap clipped = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(clipped); final float radius = width > height ? height / 2 : width / 2; canvas.drawCircle(width / 2, height / 2, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN)); Bitmap rounded = Bitmap.createBitmap(width, height, Config.ARGB_8888); canvas = new Canvas(rounded); canvas.drawBitmap(source, 0, 0, null); canvas.drawBitmap(clipped, 0, 0, paint); source.recycle(); clipped.recycle(); return rounded; }
From source file:Main.java
public static Bitmap forceEvenBitmapSize(Bitmap original) { int width = original.getWidth(); int height = original.getHeight(); if (width % 2 == 1) { width++;// w ww. j a v a2s. co m } if (height % 2 == 1) { height++; } Bitmap fixedBitmap = original; if (width != original.getWidth() || height != original.getHeight()) { fixedBitmap = Bitmap.createScaledBitmap(original, width, height, false); } if (fixedBitmap != original) { original.recycle(); } return fixedBitmap; }
From source file:Main.java
public static Bitmap compressFixBitmap(Bitmap bitMap, int outWidth, int outHeight) { int width = bitMap.getWidth(); int height = bitMap.getHeight(); float scaleWidth = ((float) outWidth) / width; float scaleHeight = ((float) outHeight) / height; Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); return Bitmap.createBitmap(bitMap, 0, 0, width, height, matrix, true); }
From source file:Main.java
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) { final int w = bm.getWidth(); final int h = bm.getHeight(); final float sw = ((float) newWidth) / w; final float sh = ((float) newHeight) / h; Matrix matrix = new Matrix(); matrix.postScale(sw, sh);//from w w w. ja v a2 s . com return Bitmap.createBitmap(bm, 0, 0, w, h, matrix, false); }
From source file:Main.java
public static Bitmap scale(Bitmap b, int reqWidth, int reqHeight) { Matrix m = new Matrix(); if (b.getWidth() > b.getHeight()) { reqWidth = (int) (reqHeight * (1.0 * b.getWidth() / b.getHeight())); } else {//from ww w .j a v a 2s . co m reqHeight = (int) (reqWidth * (1.0 * b.getHeight() / b.getWidth())); } m.setRectToRect(new RectF(0, 0, b.getWidth(), b.getHeight()), new RectF(0, 0, reqWidth, reqHeight), Matrix.ScaleToFit.CENTER); return Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true); }
From source file:Main.java
private static Bitmap resizeBitmap(Bitmap bmp, float width, float height) { float xscale = width / bmp.getWidth(); float yscale = height / bmp.getHeight(); Matrix matrix = new Matrix(); // resize original image matrix.postScale(xscale, yscale);/*from w w w . j a v a 2s . c o m*/ Bitmap dstbmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); return dstbmp; }
From source file:Main.java
/** * Method to remove color in a Bitmap, creating a gray scale image. * * @param bmpOriginal The original Bitmap. * @return The gray scale Bitmap.//from w ww .jav a2 s . c o m */ public static Bitmap toGrayscale(Bitmap bmpOriginal) { Bitmap bmpGrayscale = Bitmap.createBitmap(bmpOriginal.getWidth(), bmpOriginal.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmpGrayscale); Paint paint = new Paint(); paint.setAntiAlias(true); ColorMatrix cm = new ColorMatrix(); cm.setSaturation(0); ColorMatrixColorFilter colorMatrixColorFilter = new ColorMatrixColorFilter(cm); paint.setColorFilter(colorMatrixColorFilter); canvas.drawBitmap(bmpOriginal, 0, 0, paint); return bmpGrayscale; }