List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_90
int ORIENTATION_ROTATE_90
To view the source code for android.media ExifInterface ORIENTATION_ROTATE_90.
Click Source Link
From source file:Main.java
public static int getOrientationFromExif(String imagePath) { int orientation = 0; try {//from ww w .ja v a 2 s.com ExifInterface exif = new ExifInterface(imagePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_270: orientation = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: orientation = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: orientation = 90; break; case ExifInterface.ORIENTATION_NORMAL: orientation = 0; break; default: break; } } catch (Exception e) { } return orientation; }
From source file:Main.java
/** * <pre>/*from w ww. j av a 2s .c o m*/ * Get rotation angle of an image. * This information is stored in image file. Therefore, this method needs path to file, not a {@link Bitmap} object or byte array. * </pre> * @param imagePath absolute path to image file * @return one of 0, 90, 180, 270 */ public static int getImageRotateAngle(String imagePath) throws IOException { ExifInterface exif = new ExifInterface(imagePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int angle = 0; if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { angle = 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { angle = 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { angle = 270; } return angle; }
From source file:Main.java
public static int getRotatedDegree(String path) { int rotate = 0; try {//from w w w. ja v a2s .c o m ExifInterface exifInterface = new ExifInterface(path); int result = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (result) { 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: break; } } catch (Exception e) { e.printStackTrace(); } return rotate; }
From source file:Main.java
/** * This method resets bitmap orientation to 0 if not. * /* w ww. j a va2s . c om*/ * @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 int[] getRotation(String imgPath) { int[] rs = new int[2]; int rotation = 0; int flip = 0; try {/*from w ww . j a va 2 s . c o m*/ 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
/** * Returns a matrix with rotation set based on Exif orientation tag. * If the orientation is undefined or 0 null is returned. * * @param pathToOriginal Path to original image file that may have exif data. * @return A rotation in degrees based on exif orientation *//*from www . ja v a 2 s . co m*/ public static int getOrientation(String pathToOriginal) { int degreesToRotate = 0; try { ExifInterface exif = new ExifInterface(pathToOriginal); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); if (orientation == ExifInterface.ORIENTATION_ROTATE_90) { degreesToRotate = 90; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) { degreesToRotate = 180; } else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) { degreesToRotate = 270; } } catch (Exception e) { if (Log.isLoggable(TAG, Log.ERROR)) { Log.e(TAG, "Unable to get orientation for image with path=" + pathToOriginal, e); } } return degreesToRotate; }
From source file:Main.java
/** * Adjust the photo orientation//ww w .j a v a 2 s . c om * @param pathToFile * @return */ public static Bitmap adjustPhotoOrientation(String pathToFile) { try { Bitmap bitmap = BitmapFactory.decodeFile(pathToFile); ExifInterface exif = new ExifInterface(pathToFile); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); int rotate = 0; switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; } if (rotate != 0) { int w = bitmap.getWidth(); int h = bitmap.getHeight(); // Setting pre rotate Matrix mtx = new Matrix(); mtx.preRotate(rotate); // Rotating Bitmap & convert to ARGB_8888, required by tess bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false); bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true); return bitmap; } } catch (IOException e) { e.printStackTrace(); } return null; }
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/*from ww w . j a va2 s.c o 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
static public Bitmap getOrientedBitmapFromBitmapAndPath(Bitmap bitmap, String filePath) { Log.d(TAG, "[AirImagePickerUtils] Entering getOrientedBitmapFromBitmapAndPath"); try {/*from www.j a va 2s .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
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) { int rotate = 0; try {//ww w .ja v a 2 s .c o m context.getContentResolver().notifyChange(imageUri, null); File imageFile = new File(imagePath); ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_270: rotate = 270; break; case ExifInterface.ORIENTATION_ROTATE_180: rotate = 180; break; case ExifInterface.ORIENTATION_ROTATE_90: rotate = 90; break; } } catch (Exception e) { e.printStackTrace(); } return rotate; }