List of usage examples for android.graphics Bitmap createBitmap
public static Bitmap createBitmap(@NonNull DisplayMetrics display, @NonNull @ColorInt int[] colors, int offset, int stride, int width, int height, @NonNull Config config)
From source file:Main.java
/** * Get a mirror Bitmap//w ww . j ava2s . c o m * * @param sourceBitmap Bitmap to Change * @return Mirror bitmap */ public static Bitmap getMirrorBitmap(Bitmap sourceBitmap) { Matrix m = new Matrix(); m.preScale(-1, 1); Bitmap dst = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), m, false); dst.setDensity(DisplayMetrics.DENSITY_DEFAULT); return dst; }
From source file:Main.java
public static Bitmap resizeBitmap(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float scaleWidth = ((float) w) / width; float scaleHeight = ((float) h) / 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 getSolideSizeBitmap(Bitmap bm, int width, int height) { float widthScale = (width * 1f) / (bm.getWidth() * 1f); float heightScale = (height * 1f) / (bm.getHeight() * 1f); Matrix matrix = new Matrix(); matrix.setScale(widthScale, heightScale); return Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, false); }
From source file:Main.java
public static Bitmap getResizedBitmap(Bitmap bitmap, int i, int j) { int k = bitmap.getWidth(); int l = bitmap.getHeight(); float f = (float) i / (float) k; float f1 = (float) j / (float) l; Matrix matrix = new Matrix(); matrix.postScale(f, f1);/* ww w. j av a2s . c o m*/ return Bitmap.createBitmap(bitmap, 0, 0, k, l, matrix, false); }
From source file:Main.java
public static Bitmap rotate(Bitmap originalBitmap, float alpha) { if (originalBitmap == null) return null; int width = originalBitmap.getWidth(); int height = originalBitmap.getHeight(); Matrix matrix = new Matrix(); matrix.setRotate(alpha);/*ww w . ja v a 2 s.c o m*/ return Bitmap.createBitmap(originalBitmap, 0, 0, width, height, matrix, true); }
From source file:Main.java
public static Bitmap bitmapZoomByScale(Bitmap srcBitmap, float scaleWidth, float scaleHeight) { int srcWidth = srcBitmap.getWidth(); int srcHeight = srcBitmap.getHeight(); Matrix matrix = new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizedBitmap = Bitmap.createBitmap(srcBitmap, 0, 0, srcWidth, srcHeight, matrix, true); if (resizedBitmap != null) { srcBitmap = null;//from w w w. j a v a 2s.c o m return resizedBitmap; } else { return srcBitmap; } }
From source file:Main.java
public final static Bitmap rotationBitmap(Bitmap srcBitmap, float degrees) { Bitmap result = null;/*from www. ja v a 2s . c o m*/ if (degrees != 0 && srcBitmap != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) srcBitmap.getWidth() / 2, (float) srcBitmap.getHeight() / 2); try { Bitmap b2 = Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(), srcBitmap.getHeight(), m, true); if (srcBitmap != b2) { srcBitmap.recycle(); srcBitmap = b2; } result = b2; } catch (OutOfMemoryError ex) { ex.printStackTrace(); } } return result; }
From source file:Main.java
public static Bitmap fixRotateMirrorImage(Bitmap src) { Matrix rotateRight = new Matrix(); float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1 }; Matrix matrixMirrorY = new Matrix(); matrixMirrorY.setValues(mirrorY);// w w w .j av a2 s.co m rotateRight.postConcat(matrixMirrorY); rotateRight.preRotate(270); final Bitmap rotMirrorImg = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), rotateRight, true); src.recycle(); return rotMirrorImg; }
From source file:Main.java
public static Bitmap getRotatedBitmap(byte[] bildDaten) { Bitmap result = BitmapFactory.decodeByteArray(bildDaten, 0, bildDaten.length); if (result.getWidth() > result.getHeight()) { Matrix m = new Matrix(); m.postRotate(90);/*from w w w . ja va2 s . co m*/ result = Bitmap.createBitmap(result, 0, 0, result.getWidth(), result.getHeight(), m, true); } return result; }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float x = (float) w / width; float y = (float) h / height; matrix.postScale(x, y);// www .j a va 2 s.c o m Bitmap zoomBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return zoomBitmap; }