List of usage examples for android.graphics Matrix setRotate
public void setRotate(float degrees, float px, float py)
From source file:Main.java
private static Bitmap rotate(Bitmap result, int rotation) { Matrix matrix = new Matrix(); matrix.setRotate(rotation, (float) result.getWidth() / 2, (float) result.getHeight() / 2); return Bitmap.createBitmap(result, 0, 0, result.getWidth(), result.getHeight(), matrix, true); }
From source file:Main.java
public static Bitmap rotateBitmap(int degrees, Bitmap bitmap) { if (degrees == 0 || null == bitmap) { return bitmap; }/* w ww. jav a 2 s. co m*/ Matrix matrix = new Matrix(); matrix.setRotate(degrees, bitmap.getWidth() / 2, bitmap.getHeight() / 2); Bitmap bmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); if (null != bitmap) { bitmap.recycle(); bitmap = null; } return bmp; }
From source file:Main.java
public final static Bitmap rotate(Bitmap b, float degrees) { if (degrees != 0 && b != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2); Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true); if (b != b2) { b.recycle();/* w w w . ja v a2 s .c om*/ b = b2; } } return b; }
From source file:Main.java
public static Bitmap rotate(Bitmap b, int degrees) { if (degrees != 0 && b != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2); try {//from ww w. j ava2 s. c o m Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true); if (b != b2) { return b2; } else { return b; } } catch (OutOfMemoryError ex) { return b; } } return null; }
From source file:Main.java
public synchronized static Bitmap getRotatedBitmap(Bitmap bitmap, int degrees) { if (degrees != 0 && bitmap != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); try {//from w w w . ja va 2s .c o m Bitmap b2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (bitmap != b2) { bitmap.recycle(); bitmap = b2; } } catch (OutOfMemoryError e) { // Log.d(PhotoUtil.class.getSimpleName(), // "Error: "+e.getMessage()); } } return bitmap; }
From source file:Main.java
public final static Bitmap rotationBitmap(Bitmap srcBitmap, float degrees) { Bitmap result = null;//from w w w . ja va 2s . co 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 rotateBitmapNoRecycle(Bitmap b, int degrees) { if (degrees != 0 && b != null && !b.isRecycled()) { Matrix m = new Matrix(); m.setRotate(degrees, (float) b.getWidth() / 2, (float) b.getHeight() / 2); try {/*from w w w. jav a 2 s .c o m*/ Bitmap b2 = Bitmap.createBitmap(b, 0, 0, b.getWidth(), b.getHeight(), m, true); return b2; } catch (OutOfMemoryError ex) { } } return b; }
From source file:Main.java
public static Bitmap rotate(Bitmap bitmap, int degrees) { if (degrees != 0 && bitmap != null) { Matrix m = new Matrix(); m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2); try {// w w w .j a v a 2 s . c o m Bitmap converted = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); if (bitmap != converted) { bitmap.recycle(); bitmap = converted; } } catch (OutOfMemoryError ex) { // if out of memory, return original bitmap } } return bitmap; }
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 w ww. j a va2 s . c om 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();//from www .ja va2 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); return bm1; }