照片选择器。纵向转向横向

来源:互联网 发布:汽车模拟驾驶软件 编辑:程序博客网 时间:2024/06/10 01:01


照片选择器。纵向转向横向

1. 你必须得到该图片的EXIF旋转,这样的安排youur相应

public static int getExifRotation(String imgPath) { try  {  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; }}

得到的图像的路径

public String getPath(Uri uri) { String[] projection = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(uri, projection, null, null, null); int column_index = cursor   .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index);}

薄做一个矩阵构造矩阵

Matrix matrix = new Matrix();matrix.preRotate(90); // ormatrix.postRotate(90);

所以你的onActivityResult里面你应该有这样的

 Uri selectedImageUri = data.getData();    selectedImagePath = getPath(selectedImageUri);    orientation = getExifRotation(selectedImagePath);    Matrix matrix = new Matrix();    matrix.postRotate(90);    if(orientation == 90){     bitmap = Bitmap.createBitmap(bitmap, 0, 0,        bitmap.getWidth(), bitmap.getHeight(),        matrix, true);}

确保你重新取样图像第一了,所以他怎么有它在他的答案,然后再做到这一点

0 0