List of usage examples for android.media ExifInterface ORIENTATION_UNDEFINED
int ORIENTATION_UNDEFINED
To view the source code for android.media ExifInterface ORIENTATION_UNDEFINED.
Click Source Link
From source file:Main.java
private static int getExifOrientation(String filePath) { int degree = 0; try {/*from www.ja va 2s.c om*/ ExifInterface exif = new ExifInterface(filePath); int result = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (result) { case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; break; default: break; } } catch (IOException e) { e.printStackTrace(); } return degree; }
From source file:Main.java
public static int getRotationFromExif(Context context, String bitmapPath) { try {//from w w w . j a va 2 s . com ExifInterface ei = new ExifInterface(bitmapPath); int exifOrientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); switch (exifOrientation) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; case ExifInterface.ORIENTATION_NORMAL: return 0; } } catch (Exception e) { } return -1; }
From source file:Main.java
public static int getExifRotation(File imageFile) { if (imageFile == null) return 0; try {//w ww . j ava2s.c o m ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath()); // We only recognize a subset of orientation tag values switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)) { case ExifInterface.ORIENTATION_ROTATE_90: return 90; case ExifInterface.ORIENTATION_ROTATE_180: return 180; case ExifInterface.ORIENTATION_ROTATE_270: return 270; default: return ExifInterface.ORIENTATION_UNDEFINED; } } catch (IOException e) { return 0; } }
From source file:Main.java
public static int getRotationAngle(String photoPath) { ExifInterface ei = null;/*from w w w . j a 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 w w w . j a va 2 s .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
/** * 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 ww. ja v a2 s . com 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
public static int getOrientationFromExif(File imgFile) throws IOException { ExifInterface exif = new ExifInterface(imgFile.getCanonicalPath()); return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); }
From source file:Main.java
public static int readPictureDegree(String path) { int degree = 0; try {//from w w w . j av a 2 s. 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; }
From source file:Main.java
public static void fixBitmapRotationExif(String filePath, Activity activityForScreenOrientation) { try {/* ww w . j a va2s . co m*/ ExifInterface exif = new ExifInterface(filePath); int exifOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (exifOrientation == ExifInterface.ORIENTATION_UNDEFINED && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc")) return; boolean flippedHorizontally = false, flippedVertically = false; int angle = 0; if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) { angle += 90; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) { angle += 180; } else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) { angle += 270; } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { flippedHorizontally = true; } else if (exifOrientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { flippedVertically = true; } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSPOSE) { angle += 90; flippedVertically = true; } else if (exifOrientation == ExifInterface.ORIENTATION_TRANSVERSE) { angle -= 90; flippedVertically = true; } int orientation; if (activityForScreenOrientation != null) { orientation = getScreenOrientation(activityForScreenOrientation); if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { angle += 90; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { angle += 180; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { angle += 270; } } orientation = 0; angle = angle % 360; if (angle == -90 && flippedVertically && !flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSVERSE; } else if (angle == -270 && flippedVertically && !flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSPOSE; } else if (angle == -90 && !flippedVertically && flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSPOSE; } else if (angle == -270 && !flippedVertically && flippedHorizontally) { orientation = ExifInterface.ORIENTATION_TRANSVERSE; } else { while (angle < 0) { angle += 360; } switch (angle) { case 0: if (flippedHorizontally) { orientation = ExifInterface.ORIENTATION_FLIP_HORIZONTAL; } else if (flippedVertically) { orientation = ExifInterface.ORIENTATION_FLIP_VERTICAL; } break; case 90: orientation = ExifInterface.ORIENTATION_ROTATE_90; break; case 180: orientation = ExifInterface.ORIENTATION_ROTATE_180; break; case 270: orientation = ExifInterface.ORIENTATION_ROTATE_270; break; } } if (orientation != exifOrientation) { exif.setAttribute(ExifInterface.TAG_ORIENTATION, ((Integer) orientation).toString()); exif.saveAttributes(); } } catch (IOException e) { Log.w("TAG", "-- Error in setting image"); } }
From source file:Main.java
public static Bitmap getBitmapByFixingRotationForFile(String filePath, Bitmap sourceBitmap, Activity activityForScreenOrientation, boolean freeSourceBitmap) { try {//from w ww . jav a 2 s. com ExifInterface exif = new ExifInterface(filePath); int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (orientation == ExifInterface.ORIENTATION_UNDEFINED && Build.MANUFACTURER.toLowerCase(Locale.ENGLISH).contains("htc")) return null; boolean flippedHorizontally = false, flippedVertically = false; 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; } else if (orientation == ExifInterface.ORIENTATION_FLIP_HORIZONTAL) { flippedHorizontally = true; } else if (orientation == ExifInterface.ORIENTATION_FLIP_VERTICAL) { flippedVertically = true; } else if (orientation == ExifInterface.ORIENTATION_TRANSPOSE) { angle += 90; flippedVertically = true; } else if (orientation == ExifInterface.ORIENTATION_TRANSVERSE) { angle -= 90; flippedVertically = true; } if (activityForScreenOrientation != null) { orientation = getScreenOrientation(activityForScreenOrientation); if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { angle += 90; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE) { angle += 180; } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) { angle += 270; } } Bitmap bmp = sourceBitmap; if (bmp == null) { bmp = BitmapFactory.decodeFile(filePath, null); } if (angle != 0) { Matrix mat = new Matrix(); mat.postRotate(angle); if (flippedHorizontally) { mat.postScale(-1.f, 1.f); } if (flippedVertically) { mat.postScale(1.f, -1.f); } Bitmap rotated = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), mat, true); if (freeSourceBitmap || bmp != sourceBitmap) { bmp.recycle(); } bmp = rotated; } return bmp; } catch (IOException e) { Log.w("TAG", "-- Error in setting image"); } catch (OutOfMemoryError oom) { Log.w("TAG", "-- OOM Error in setting image"); } return null; }