List of usage examples for android.graphics Matrix postRotate
public boolean postRotate(float degrees)
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap source, int rotation, boolean recycle) { if (rotation == 0) return source; int w = source.getWidth(); int h = source.getHeight(); Matrix m = new Matrix(); m.postRotate(rotation); Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, w, h, m, true); if (recycle)// w w w. j a v a2 s . c o m source.recycle(); return bitmap; }
From source file:Main.java
public static Bitmap getRotatedBitmap(Bitmap imageBitmap, int screenRotation) { int rotationAdjustment = getRotationAdjustment(screenRotation); Matrix matrix = new Matrix(); matrix.postRotate(rotationAdjustment); return Bitmap.createBitmap(imageBitmap, 0, 0, imageBitmap.getWidth(), imageBitmap.getHeight(), matrix, true);//from w ww .j a v a2s . c om }
From source file:Main.java
public static Bitmap scaleBitmap(int height, int width, String pathImage) { Bitmap desBitmap = null;/*from w w w . ja v a 2s . co m*/ BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathImage, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / width, photoH / height); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor << 1; bmOptions.inPurgeable = true; Bitmap bitmap = BitmapFactory.decodeFile(pathImage, bmOptions); Matrix mtx = new Matrix(); mtx.postRotate(90); // Rotating Bitmap Bitmap rotatedBMP = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mtx, true); if (rotatedBMP != bitmap) { bitmap.recycle(); } return rotatedBMP; }
From source file:Main.java
public static Bitmap getRotatedImg(String path) { int angle = getBitmapRotation(path); Matrix matrix = new Matrix(); matrix.postRotate(angle); Bitmap bitmap = BitmapFactory.decodeFile(path); try {/*from w w w . ja v a2 s . c o m*/ bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } catch (Exception e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
/** * Rotates a bitmap by a certain angle/* w ww .ja v a 2 s .c o m*/ * * @param pSourceBitmap * The bitmap that needs to be rotated * @param pAngle * The angle the bitmap should be rotated to * @return A rotated bitmap */ private static Bitmap rotateImage(Bitmap pSourceBitmap, float pAngle) { Bitmap bitmap = null; Matrix matrix = new Matrix(); matrix.postRotate(pAngle); try { bitmap = Bitmap.createBitmap(pSourceBitmap, 0, 0, pSourceBitmap.getWidth(), pSourceBitmap.getHeight(), matrix, true); } catch (OutOfMemoryError err) { err.printStackTrace(); } return bitmap; }
From source file:Main.java
/** * This method resets bitmap orientation to 0 if not. * /*from w ww . j ava 2s. c o m*/ * @param path * @param bitmap * @return bitmap with 0 degree orientation */ public static Bitmap resetBitmapOrientation(String path, Bitmap bitmap) { // TODO Auto-generated method stub int rotate = 0; try { ExifInterface ei = new ExifInterface(path); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; default: // do nothing... break; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (rotate == 0) { return bitmap; } else { Matrix m = new Matrix(); m.postRotate(rotate); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); } }
From source file:Main.java
public static Bitmap rotateBitmap(Bitmap bm, int direction) { Bitmap returnBm;//from www. j a va 2 s . c om int w = bm.getWidth(); int h = bm.getHeight(); Matrix matrix = new Matrix(); if (direction == ROTATE_LEFT) { matrix.postRotate(-90); } else if (direction == ROTATE_RIGHT) { matrix.postRotate(90); } returnBm = Bitmap.createBitmap(bm, 0, 0, w, h, matrix, true); if (bm != returnBm) { bm.recycle(); } return returnBm; }
From source file:Main.java
public static Bitmap rotateImage(Bitmap bitmap, float degrees) { Bitmap resultBitmap = bitmap;//from www .j a va2 s . 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 processToteImage(String image_path, Bitmap bm) { Bitmap bitmap = null;//ww w . ja v a 2s . co m try { ExifInterface exif = new ExifInterface(image_path); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); Log.d("EXIF", "Exif: " + orientation); Matrix matrix = new Matrix(); if (orientation == 6) { matrix.postRotate(90); } else if (orientation == 3) { matrix.postRotate(180); } else if (orientation == 8) { matrix.postRotate(270); } bitmap = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); // rotating // bitmap } catch (Exception e) { } return bitmap; }
From source file:Main.java
public static Bitmap imageWithFixedRotation(Bitmap bm, int degrees) { if (bm == null || bm.isRecycled()) return null; if (degrees == 0) return bm; final Matrix matrix = new Matrix(); matrix.postRotate(degrees); Bitmap result = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); if (result != bm) bm.recycle();/* w ww .ja v a 2 s . co m*/ return result; }