我一直在试图弄清楚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_REQUEST如下
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();
}
}
}
最后,这就是在控制台内部阅读的内容。
System.out: image.png (No such file or directory)
对此的任何帮助将不胜感激!! 感谢
答案 0 :(得分:0)
FileHelper.getFileName()
几乎肯定是错误的,因为Uri
无需表示文件。我强烈建议你完全摆脱它。
使用ContentResolver
(来自getContentResolver()
上的Activity
)和openInputStream()
获取InputStream
标识的内容Uri
。您可以将其传递给a constructor on the support library edition of ExifInterface
以尝试获取方向标记(如果存在)。
答案 1 :(得分:0)
你应该使用compat ExifInterface。
com.android.support:exifinterface:${lastLibVersion}
您将能够使用InputStream
(来自ContentResolver
)而不是uri路径来实例化ExifInterface(pior API&lt; 24),而不是“文件未找到异常”
https://android-developers.googleblog.com/2016/12/introducing-the-exifinterface-support-library.html