List of usage examples for android.graphics Matrix setRotate
public void setRotate(float degrees)
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); return Bitmap.createBitmap(originalBitmap, 0, 0, width, height, matrix, true); }
From source file:Main.java
public static Bitmap rotateBitmapDegrees(Bitmap bitmap, int orientation) { if (orientation == 0) { return bitmap; }/*from w w w. j a va2 s . co m*/ Matrix matrix = new Matrix(); matrix.setRotate(orientation); Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.recycle(); return bmRotated; }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bitmap, float degrees) { Bitmap resizeBmp = null;/*from ww w . j a v a 2 s. c o m*/ if (bitmap != null && degrees > 0) { Matrix matrix = new Matrix(); matrix.setRotate(degrees); resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } return resizeBmp; }
From source file:Main.java
/** * For rotating images//from w w w. jav a 2 s . c o m * @param bitmap Bitmap to rotate * @param degree Degree amount to rotate * @return */ public static Bitmap rotate(Bitmap bitmap, int degree) { if (bitmap == null) { return null; } int w = bitmap.getWidth(); int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.setRotate(degree); return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bitmap, float degrees) { Bitmap mBitmap = null;//w w w.ja v a 2 s . com try { Matrix m = new Matrix(); m.setRotate(degrees % 360); mBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, false); } catch (Exception e) { e.printStackTrace(); } return mBitmap; }
From source file:Main.java
public static Bitmap roateBitmap(Bitmap bitmap, int roatation) { Matrix matrix = new Matrix(); matrix.setRotate(roatation); if (bitmap == null) { return null; }//from w ww . ja v a2s . co m try { return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (OutOfMemoryError e) { return bitmap; } }
From source file:Main.java
/** * This is an expensive operation that copies the image in place with the pixels rotated. * If possible rather use getOrientationMatrix, and set that as the imageMatrix on an ImageView. * * @param imageToOrient Image Bitmap to orient. * @param degreesToRotate number of degrees to rotate the image by. If zero the original image is returned unmodified. * @return The oriented bitmap. May be the imageToOrient without modification, or a new Bitmap. *//*from w w w . j av a 2 s . c o m*/ public static Bitmap rotateImage(Bitmap imageToOrient, int degreesToRotate) { try { if (degreesToRotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(degreesToRotate); imageToOrient = Bitmap.createBitmap(imageToOrient, 0, 0, imageToOrient.getWidth(), imageToOrient.getHeight(), matrix, true); } } catch (Exception e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Exception when trying to orient image", e); } e.printStackTrace(); } return imageToOrient; }
From source file:Main.java
public static Bitmap orientationBitMap(String filepath, Bitmap bit) { int orientation = getExifOrientation(filepath); if (orientation != 0) { Matrix matrix = new Matrix(); matrix.setRotate(orientation); return Bitmap.createBitmap(bit, 0, 0, bit.getWidth(), bit.getHeight(), matrix, true); }//w w w . ja va2s . c o m return bit; }
From source file:Main.java
/** * This is an expensive operation that copies the image in place with the pixels rotated. If * possible rather use getOrientationMatrix, and put that as the imageMatrix on an ImageView. * * @param imageToOrient Image Bitmap to orient. * @param degreesToRotate number of degrees to rotate the image by. If zero the original image is * returned unmodified. * @return The oriented bitmap. May be the imageToOrient without modification, or a new Bitmap. *//* ww w .j a v a 2s . c om*/ public static Bitmap rotateImage(@NonNull Bitmap imageToOrient, int degreesToRotate) { Bitmap result = imageToOrient; try { if (degreesToRotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(degreesToRotate); result = Bitmap.createBitmap(imageToOrient, 0, 0, imageToOrient.getWidth(), imageToOrient.getHeight(), matrix, true /*filter*/); } } catch (Exception e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Exception when trying to orient image", e); } } return result; }
From source file:Main.java
public static String writeBitmap(byte[] data, int cameraDegree, Rect rect, Rect willTransformRect) throws IOException { File file = new File(Environment.getExternalStorageDirectory() + "/bookclip/"); file.mkdir();//from ww w .j a v a 2s . c o m String bitmapPath = file.getPath() + "/" + System.currentTimeMillis() + ".png"; // bitmap rotation, scaling, crop BitmapFactory.Options option = new BitmapFactory.Options(); option.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, option); Matrix bitmapMatrix = new Matrix(); bitmapMatrix.setRotate(cameraDegree); int x = rect.left, y = rect.top, width = rect.right - rect.left, height = rect.bottom - rect.top; Bitmap rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmapMatrix, false); // bitmap recycle bitmap.recycle(); Bitmap scaledBitmap = Bitmap.createScaledBitmap(rotateBitmap, willTransformRect.right, willTransformRect.bottom - willTransformRect.top, false); // rotatebitmap recycle rotateBitmap.recycle(); Bitmap cropBitmap = Bitmap.createBitmap(scaledBitmap, x, y, width, height, null, false); // scaledBitmap recycle scaledBitmap.recycle(); // file write FileOutputStream fos = new FileOutputStream(new File(bitmapPath)); cropBitmap.compress(CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); // recycle cropBitmap.recycle(); return bitmapPath; }