Android 未找到Exif信息旋转获取文件异常

Android 未找到Exif信息旋转获取文件异常,android,exif,Android,Exif,我一直在试图弄清楚EXIF有一段时间了,我只是遇到了一个又一个问题,一个又一个问题。我希望有人能为我解释一下 我有一个按钮,一个用户按下,它这样做的目的 Intent intent = new Intent(); // Show only images, no videos or anything else intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); // Always show the choo

我一直在试图弄清楚EXIF有一段时间了,我只是遇到了一个又一个问题,一个又一个问题。我希望有人能为我解释一下

我有一个按钮,一个用户按下,它这样做的目的

Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
PICK_IMAGE_请求如下

private int PICK_IMAGE_REQUEST = 1;
这是我的OnActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {

        mMediaUri = data.getData();

        try {
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mMediaUri);

            String fileName2 = FileHelper.getFileName(UserProfileActivity.this, mMediaUri, "image");
            try {
                ExifInterface exifInterface = new ExifInterface(fileName2);
                int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
                System.out.println(orientation + "---------------------------");
                Matrix matrix = new Matrix();
                if (orientation == 6) {
                    System.out.println("oritation 6, rotate 90");
                    matrix.postRotate(90);
                } else if (orientation == 3) {
                    System.out.println("oritation 3, rotate 180");
                    matrix.postRotate(180);
                } else  if (orientation == 8) {
                    System.out.println("oritation 8, rotate 270");
                    matrix.postRotate(270);
                }
                bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }

            //friendsProfilePic imageView = (ImageView) findViewById(R.id.imageView);
            if (userChangedImage){
                userProfileImage.setImageBitmap(bitmap);
            }
            userProfileImageEditProfile.setImageBitmap(bitmap);

            final ParseQuery<ParseUser> queryUser = ParseUser.getQuery();
            try {
                byte[] fileBytes = FileHelper.getByteArrayFromFile(UserProfileActivity.this, mMediaUri);
                if (fileBytes == null) {
                    //there was an error
                    Toast.makeText(getApplicationContext(), "There was an error. Try again!", Toast.LENGTH_LONG).show();
                } else {
                    fileBytes = FileHelper.reduceImageForUpload(fileBytes);
                    String fileName = FileHelper.getFileName(UserProfileActivity.this, mMediaUri, "image");
                    userChangedImageFile = new ParseFile(fileName, fileBytes);
                    userChangedImage = true;
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
在此方面的任何帮助都将不胜感激!!
谢谢

FileHelper.getFileName()
几乎肯定是错误的,因为不需要
Uri
来表示文件。我强烈建议你彻底摆脱它


使用
ContentResolver
(在
活动上的
getContentResolver()
)和
openInputStream()
Uri
标识的内容上获取
InputStream
。如果方向标记存在,您可以将其传递给尝试获取方向标记。

FileHelper.getFileName()
几乎肯定是错误的,因为不需要
Uri
来表示文件。我强烈建议你彻底摆脱它


使用
ContentResolver
(在
活动上的
getContentResolver()
)和
openInputStream()
Uri
标识的内容上获取
InputStream
。如果方向标记存在,您可以将其传递给尝试获取方向标记。

您应该使用compat ExifInterface

com.android.support:ExiFinInterface:${lastLibVersion}


您将能够实例化ExifInterface(pior)API您应该使用compat ExifInterface

com.android.support:ExiFinInterface:${lastLibVersion}


您将能够实例化ExiFinInterface(PIR)或API。您应该调试代码并查看data.getData()的实际外观。您应该调试代码并查看data.getData()的实际外观。
System.out: image.png (No such file or directory)