我有一种获取照片方向的方法,但是当在纵向模式下拍摄图像并从图库中选择后,此方法会旋转以垂直翻转。
更新
此方法现用于显示从图库
中选择的图像public static Boolean ShowImagesCapture(Context context, Uri PATH_IMAGE, ImageView view,int width, int height){
int orientation=0;
Boolean success = true;
try {
Bitmap bitmap =null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
if (Build.VERSION.SDK_INT < 19) {
String selectedImagePath = getPath(PATH_IMAGE,context);
bitmap = decodefilebitmap(selectedImagePath,bitmap.getWidth(),bitmap.getHeight());
orientation=GetPhotoOrientation(context,getRealPathFromURI(context,PATH_IMAGE));
}
else {
ParcelFileDescriptor parcelFileDescriptor;
try {
parcelFileDescriptor = context.getContentResolver().openFileDescriptor(PATH_IMAGE, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
orientation=GetPhotoOrientation(context,getRealPathFromURI(context,PATH_IMAGE));
} catch (Exception e) {
e.printStackTrace();
}
}
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_180:
bitmap=rotateBitmap(bitmap,3,width,height);
view.setImageBitmap(bitmap);
break;
case ExifInterface.ORIENTATION_ROTATE_90:
bitmap=rotateBitmap(bitmap,8,width,height);
view.setImageBitmap(bitmap);
break;
case ExifInterface.ORIENTATION_TRANSVERSE:
break;
case ExifInterface.ORIENTATION_ROTATE_270:
bitmap=rotateBitmap(bitmap,6,width,height);
view.setImageBitmap(bitmap);
break;
default:
view.setImageBitmap(bitmap);
}
bitmap = null;
}
catch (Exception e) {
e.printStackTrace();
success= false;
}
System.gc();
return success;
}