List of usage examples for android.graphics Canvas drawBitmap
public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint)
From source file:Main.java
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null); canvas.drawBitmap(bmp2, 0, 0, null); return bmOverlay; }
From source file:Main.java
public static Bitmap overlayToDownCenter(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null); Matrix matrix = new Matrix(); matrix.setTranslate(((float) bmp1.getWidth() - bmp2.getWidth()) / 2, bmp1.getHeight() - bmp2.getHeight()); canvas.drawBitmap(bmp2, matrix, null); return bmOverlay; }
From source file:Main.java
public static Bitmap overlayToDownRightCorner(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null); Matrix matrix = new Matrix(); matrix.setTranslate(bmp1.getWidth() - bmp2.getWidth(), bmp1.getHeight() - bmp2.getHeight()); canvas.drawBitmap(bmp2, matrix, null); return bmOverlay; }
From source file:Main.java
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2, float left, float top) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null); canvas.drawBitmap(bmp2, left, top, null); return bmOverlay; }
From source file:Main.java
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) { Matrix m = new Matrix(); m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); float targetX, targetY; if (orientationDegree == 90) { targetX = bm.getHeight();//from w w w .j ava 2 s . com targetY = 0; } else { targetX = bm.getHeight(); targetY = bm.getWidth(); } final float[] values = new float[9]; m.getValues(values); float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(bm1); canvas.drawBitmap(bm, m, paint); return bm1; }
From source file:Main.java
public static Drawable rotateBitmap(Bitmap inputBitmap) { Matrix matrix = new Matrix(); matrix.setRotate(90, (float) inputBitmap.getWidth() / 2, (float) inputBitmap.getHeight() / 2); float outputX = inputBitmap.getHeight(); float outputY = 0; final float[] values = new float[9]; matrix.getValues(values);//from ww w . j a v a2 s . co m float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; matrix.postTranslate(outputX - x1, outputY - y1); Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getHeight(), inputBitmap.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(outputBitmap); canvas.drawBitmap(inputBitmap, matrix, paint); return new BitmapDrawable(null, outputBitmap); }
From source file:Main.java
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) { Matrix m = new Matrix(); m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); float targetX, targetY; if (orientationDegree == 90) { targetX = bm.getHeight();// w w w .j ava2 s .c o m targetY = 0; } else { targetX = bm.getHeight(); targetY = bm.getWidth(); } final float[] values = new float[9]; m.getValues(values); float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap temp = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(temp); canvas.drawBitmap(bm, m, paint); return temp; }
From source file:Main.java
public static Bitmap adjustPhotoRotation(Bitmap bm, final int orientationDegree) { Matrix m = new Matrix(); m.setRotate(orientationDegree, (float) bm.getWidth() / 2, (float) bm.getHeight() / 2); float targetX, targetY; if (orientationDegree == 90) { targetX = bm.getHeight();//from w w w.j ava 2 s .co m targetY = 0; } else { targetX = bm.getHeight(); targetY = bm.getWidth(); } final float[] values = new float[9]; m.getValues(values); float x1 = values[Matrix.MTRANS_X]; float y1 = values[Matrix.MTRANS_Y]; m.postTranslate(targetX - x1, targetY - y1); Bitmap bm1 = Bitmap.createBitmap(bm.getHeight(), bm.getWidth(), Bitmap.Config.ARGB_8888); Paint paint = new Paint(); Canvas canvas = new Canvas(bm1); canvas.drawBitmap(bm, m, paint); bm.recycle(); bm = null; return bm1; }
From source file:Main.java
public static Bitmap rotateWithCanvas(Bitmap bitmap, int degrees) { int destWidth, destHeight; float centerX = bitmap.getWidth() / 2; float centerY = bitmap.getHeight() / 2; // We want to do the rotation at origin, but since the bounding // rectangle will be changed after rotation, so the delta values // are based on old & new width/height respectively. Matrix matrix = new Matrix(); matrix.preTranslate(-centerX, -centerY); matrix.postRotate(degrees);/*from w w w.j a va2 s .c om*/ if (degrees / 90 % 2 == 0) { destWidth = bitmap.getWidth(); destHeight = bitmap.getHeight(); matrix.postTranslate(centerX, centerY); } else { destWidth = bitmap.getHeight(); destHeight = bitmap.getWidth(); matrix.postTranslate(centerY, centerX); } Bitmap cropped = Bitmap.createBitmap(destWidth, destHeight, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(cropped); canvas.drawBitmap(bitmap, matrix, null); return cropped; }
From source file:Main.java
public static Bitmap formatBitmap(Bitmap bitmap, int size) { float width = bitmap.getWidth(); float height = bitmap.getHeight(); float rota = size / height; int widthnew = (int) ((size * width) / height); // int wh = Math.max(bitmap.getWidth(), bitmap.getHeight()); Bitmap mBitmap = Bitmap.createBitmap(widthnew, size, Bitmap.Config.ARGB_8888); Matrix matrix = new Matrix(); matrix.postScale(rota, rota);//from w w w .j av a2s . c om Canvas canvas = new Canvas(mBitmap); canvas.drawBitmap(bitmap, matrix, null); // bitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true); return mBitmap; }