List of usage examples for android.media ExifInterface ORIENTATION_ROTATE_270
int ORIENTATION_ROTATE_270
To view the source code for android.media ExifInterface ORIENTATION_ROTATE_270.
Click Source Link
From source file:Main.java
public static int getExifRotation(String imgPath) { try {/*from ww w . j a va 2s. co m*/ ExifInterface exif = new ExifInterface(imgPath); String rotationAmount = exif.getAttribute(ExifInterface.TAG_ORIENTATION); if (!TextUtils.isEmpty(rotationAmount)) { int rotationParam = Integer.parseInt(rotationAmount); switch (rotationParam) { case ExifInterface.ORIENTATION_NORMAL: return 0; case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return 0; } } else { return 0; } } catch (Exception ex) { return 0; } }
From source file:Main.java
public static Bitmap rotateByExifInfo(Bitmap source, String path) { try {/* w ww. ja va2s.c o m*/ ExifInterface exifInterface = new ExifInterface(path); String tagName = ExifInterface.TAG_ORIENTATION; int defaultValue = ExifInterface.ORIENTATION_NORMAL; int orientation = exifInterface.getAttributeInt(tagName, defaultValue); switch (orientation) { case ExifInterface.ORIENTATION_NORMAL: return source; case ExifInterface.ORIENTATION_ROTATE_90: return rotate(source, 90); case ExifInterface.ORIENTATION_ROTATE_180: return rotate(source, 180); case ExifInterface.ORIENTATION_ROTATE_270: return rotate(source, 270f); default: return source; } } catch (Exception e) { return source; } }
From source file:Main.java
/** * <pre>/* w w w . ja v a 2 s .c om*/ * 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 synchronized static int getPhotoOrientationDegree(String filepath) { int degree = 0; ExifInterface exif = null;/*from w w w .j ava2 s . co m*/ try { exif = new ExifInterface(filepath); } catch (IOException e) { // Log.d(PhotoUtil.class.getSimpleName(), "Error: "+e.getMessage()); } if (exif != null) { int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1); if (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; } } } // Log.d(PhotoUtil.class.getSimpleName(), "Photo Degree: "+degree); return degree; }
From source file:Main.java
/** * Get Image orientation from uri//from w w w . jav a2s . c o 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 getRotationAngle(String photoPath) { ExifInterface ei = null;/*from w w w .ja v a 2 s . c o m*/ try { ei = new ExifInterface(photoPath); } catch (IOException e) { Log.e(TAG, "Unexpected error occurred when getting rotation angle."); } int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (orientation) { case ExifInterface.ORIENTATION_ROTATE_90: Log.d(TAG, "90 Degrees rotation needed"); return 90; case ExifInterface.ORIENTATION_ROTATE_180: Log.d(TAG, "180 Degrees rotation needed"); return 180; case ExifInterface.ORIENTATION_ROTATE_270: Log.d(TAG, "270 Degrees rotation needed"); return 270; case ExifInterface.ORIENTATION_NORMAL: default: Log.d(TAG, "0 Degrees rotation needed"); return 0; } }
From source file:Main.java
public static int getRotatedDegree(String path) { int rotate = 0; try {//from ww w. ja v a 2s .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 ava2 s . co 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
/** * Adjust the photo orientation//from w ww. j a va 2 s.c o m * @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
/** * 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 *//* w w w . j a v a2s. c o 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; }