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
/** * Rotate the image./*from www. jav a 2s . c o m*/ * * @param drawable */ public static BitmapDrawable rotateImage(BitmapDrawable drawable, int degree) { Bitmap bitmap = drawable.getBitmap(); Matrix matrix = new Matrix(); matrix.postRotate(degree); Bitmap rotatedBMP = Bitmap.createBitmap(drawable.getBitmap(), 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); return new BitmapDrawable(rotatedBMP); }
From source file:Main.java
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) { int i = bitmap.getWidth(); int j = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1.0F, -1F);/*from w w w .j ava 2 s . c om*/ Bitmap bitmap1 = Bitmap.createBitmap(bitmap, 0, j / 2, i, j / 2, matrix, false); Bitmap bitmap2 = Bitmap.createBitmap(i, j + j / 2, android.graphics.Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap2); canvas.drawBitmap(bitmap, 0.0F, 0.0F, null); Paint paint = new Paint(); canvas.drawRect(0.0F, j, i, j + 4, paint); canvas.drawBitmap(bitmap1, 0.0F, j + 4, null); Paint paint1 = new Paint(); paint1.setShader(new LinearGradient(0.0F, bitmap.getHeight(), 0.0F, 4 + bitmap2.getHeight(), 0x70ffffff, 0xffffff, android.graphics.Shader.TileMode.CLAMP)); paint1.setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.DST_IN)); canvas.drawRect(0.0F, j, i, 4 + bitmap2.getHeight(), paint1); return bitmap2; }
From source file:Main.java
public static Bitmap zoomBMP(Bitmap bitmap, int w, int h) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = (float) w / (float) width; float scaleHeight = (float) h / (float) height; matrix.postScale(scaleWidth, scaleHeight); Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newBmp; }
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 scaleWidth = (float) w / (float) width; float scaleHeight = (float) h / (float) height; matrix.postScale(scaleWidth, scaleHeight); Bitmap newBmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newBmp; }
From source file:Main.java
/** * reversal bitmap at left-right//w w w .j ava 2 s .c om * * @param originalImage * @return the bitmap after reversal */ public static Bitmap createReversal(Bitmap originalImage) { int width = originalImage.getWidth(); int height = originalImage.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(-1.0f, 1.0f); return Bitmap.createBitmap(originalImage, 0, 0, width, height, matrix, false); }
From source file:Main.java
public static Bitmap rotateImage(Bitmap bitmap, float degrees) { Bitmap resultBitmap = bitmap;// w ww. ja v a 2s . com try { Matrix matrix = new Matrix(); matrix.postRotate(degrees); // Rotate the bitmap resultBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (Exception exception) { exception.printStackTrace(); } if (resultBitmap != bitmap) { bitmap.recycle(); } return resultBitmap; }
From source file:Main.java
public static Bitmap getRotatedImg(String path) { int angle = getBitmapRotation(path); Matrix matrix = new Matrix(); matrix.postRotate(angle);/* w w w .j a v a 2 s . c o m*/ Bitmap bitmap = BitmapFactory.decodeFile(path); try { bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h) { Bitmap newbmp = null;// w w w . j av a2 s.co m if (bitmap != null) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidht = ((float) w / width); float scaleHeight = ((float) h / height); matrix.postScale(scaleWidht, scaleHeight); newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); } return newbmp; }
From source file:Main.java
public static Bitmap scaleBitmap(Bitmap srcBitmap, int newSize) { int w = srcBitmap.getWidth(); int h = srcBitmap.getHeight(); // Determine the scaling required to get desired result. float scaleW = newSize / (float) w; float scaleH = newSize / (float) h; Matrix matrix = new Matrix(); matrix.postScale(scaleW, scaleH);/*from w w w . j a va 2s . c om*/ return Bitmap.createBitmap(srcBitmap, 0, 0, w, h, matrix, false); }
From source file:Main.java
public static Bitmap setScale(Bitmap source, int width, int height) { if (source == null || width < 1 || height < 1) { return null; }/*from w w w . j av a2s . c om*/ int w = source.getWidth(); int h = source.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = ((float) width / w); float scaleHeight = ((float) height / h); matrix.postScale(scaleWidth, scaleHeight); Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, w, h, matrix, true); return bitmap; }