Here you can find the source of getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath)
Parameter | Description |
---|---|
context | the context |
imageUri | the image uri |
imagePath | the image path |
Parameter | Description |
---|---|
IOException | Signals that an I/O exception has occurred. |
public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) throws IOException
//package com.java2s; import java.io.File; import java.io.IOException; import android.content.Context; import android.media.ExifInterface; import android.net.Uri; public class Main { /**//from www. j av a 2s.c o m * Gets the camera photo orientation. * * @param context * the context * @param imageUri * the image uri * @param imagePath * the image path * @return the camera photo orientation * @throws IOException * Signals that an I/O exception has occurred. */ public static int getCameraPhotoOrientation(Context context, Uri imageUri, String imagePath) throws IOException { int rotate = 0; context.getContentResolver().notifyChange(imageUri, null); File imageFile = new File(imagePath); ExifInterface exif = new android.media.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; } return rotate; } }