List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_180
int ORIENTATION_ROTATE_180
To view the source code for android.media ExifInterface ORIENTATION_ROTATE_180.
Click Source Link
From source file:Main.java
static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) { Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath"); try {//from ww w . j a va 2 s .com // Get orientation from EXIF ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); // Compute rotation matrix Matrix rotation = new Matrix(); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotation.preRotate(90); break; case ExifInterface.ORIENTATION_ROTATE_180: rotation.preRotate(180); break; case ExifInterface.ORIENTATION_ROTATE_270: rotation.preRotate(270); break; } // Return new bitmap Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), rotation, true); } catch (Exception exception) { Log.d(TAG, "Couldn't fix bitmap orientation: " + exception.getMessage()); Log.d(TAG, "[AirImagePickerUtils] Exiting getOrientedBitmapFromBitmapAndPath"); return bitmap; } }
From source file:Main.java
/** * Checks if the orientation of the image is correct, if it's not it will rotate the image * * @param pBitmap// w w w . j a v a2 s.co m * The bitmap to check the orientation for * @param pPath * The path to the image, used to load the exif interface * @return Bitmap in the correct orientation */ public static Bitmap imageOreintationValidator(Bitmap pBitmap, String pPath) { ExifInterface ei; try { ei = new ExifInterface(pPath); int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: pBitmap = rotateImage(pBitmap, 90); break; case ExifInterface.ORIENTATION_ROTATE_180: pBitmap = rotateImage(pBitmap, 180); break; case ExifInterface.ORIENTATION_ROTATE_270: pBitmap = rotateImage(pBitmap, 270); break; } } catch (IOException e) { e.printStackTrace(); } return pBitmap; }
From source file:Main.java
public static int[] getRotation(String imgPath) { int[] rs = new int[2]; int rotation = 0; int flip = 0; try {/*from w ww.j av a2 s.com*/ ExifInterface exif = new ExifInterface(imgPath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_FLIP_HORIZONTAL: flip = 1; case ExifInterface.ORIENTATION_NORMAL: rotation = 0; break; case ExifInterface.ORIENTATION_TRANSVERSE: flip = 1; case ExifInterface.ORIENTATION_ROTATE_90: rotation = 90; break; case ExifInterface.ORIENTATION_FLIP_VERTICAL: flip = 1; case ExifInterface.ORIENTATION_ROTATE_180: rotation = 180; break; case ExifInterface.ORIENTATION_TRANSPOSE: flip = 1; case ExifInterface.ORIENTATION_ROTATE_270: rotation = 270; break; } } catch (IOException e) { e.printStackTrace(); } rs[0] = rotation; rs[1] = flip; return rs; }
From source file:Main.java
/** * Get the orientation rotate degree of an image file. * /*from w w w .ja v a2s . c o m*/ * @param soureFilePath * The file path of the image. * @return The orientation rotate degree of an image file(90 or 180 or 270). <br> * 0, if the image file has no orientation rotate degree or the * source file is not a valid image file. */ public static int getOrientationRotateDegree(String soureFilePath) { if (null == soureFilePath) { return 0; } try { ExifInterface exif = new ExifInterface(soureFilePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: { return 90; } case ExifInterface.ORIENTATION_ROTATE_180: { return 180; } case ExifInterface.ORIENTATION_ROTATE_270: { return 270; } default: { return 0; } } } catch (IOException e) { e.printStackTrace(); return 0; } }
From source file:Main.java
/** * Get Image orientation from uri// www . ja va 2s . co m * * @param context Context of image * @param photoUri Uri of image * @return */ public static int getOrientation(Context context, Uri photoUri) { Cursor cursor = context.getContentResolver().query(photoUri, new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); try { if (cursor.moveToFirst()) { if (cursor.getInt(0) == ORIENTATION_270) return ExifInterface.ORIENTATION_ROTATE_270; else if (cursor.getInt(0) == ORIENTATION_180) return ExifInterface.ORIENTATION_ROTATE_180; else if (cursor.getInt(0) == ORIENTATION_90) return ExifInterface.ORIENTATION_ROTATE_90; } } finally { cursor.close(); } return -1; }
From source file:Main.java
public static int getDegress(String path) { int degree = 0; try {/* w ww .j a v a 2 s. c o m*/ ExifInterface exifInterface = new ExifInterface(path); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
/** * Scale a bitmap and correct the dimensions * * @param bitmap Bitmap to scale/*from w w w .j av a 2s .c o m*/ * @param width width for scaling * @param height height for scaling * @param orientation Current orientation of the Image * @return Scaled bitmap */ public static Bitmap getScaledBitmap(Bitmap bitmap, int width, int height, int orientation) { Matrix m = new Matrix(); m.setRectToRect(new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()), new RectF(0, 0, width, height), Matrix.ScaleToFit.CENTER); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { m.postRotate(ORIENTATION_90); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { m.postRotate(ORIENTATION_180); } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { m.postRotate(ORIENTATION_270); } return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true); }
From source file:Main.java
public static int getRotateDegree(String path) { int result = 0; try {//from w w w . j a v a 2 s.co m ExifInterface exif = new ExifInterface(path); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: result = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: result = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: result = 270; break; } } catch (IOException ignore) { return 0; } return result; }
From source file:Main.java
private static Bitmap turnPic(final String path, Bitmap bitmap) { ExifInterface exif;/*www.j a v a2 s . c o m*/ final int ninetyDegrees = 90; int rotationAngle = 0; Matrix matrix = new Matrix(); if (path != null) { try { exif = new ExifInterface(path); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotationAngle = ninetyDegrees; break; case ExifInterface.ORIENTATION_ROTATE_180: rotationAngle = ninetyDegrees * 2; break; case ExifInterface.ORIENTATION_ROTATE_270: rotationAngle = ninetyDegrees * 3; break; case ExifInterface.ORIENTATION_NORMAL: default: break; } } catch (IOException e) { e.printStackTrace(); return bitmap; } if (rotationAngle != 0) { matrix.postRotate(rotationAngle); } bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } return bitmap; }
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {// w w w. j a v a 2s .c o m ExifInterface exifInterface = new ExifInterface(path); int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; case ExifInterface.ORIENTATION_NORMAL: degree = 0; break; case ExifInterface.ORIENTATION_UNDEFINED: degree = 0; break; case -1: degree = 0; break; } } catch (IOException e) { e.printStackTrace(); } return degree; }