在过去一个月左右的时间里,我一直断断续续地与这个错误作斗争。每当我认为我已经解决了它,它似乎就会以某种形式回来。
这是旧的 Android“图像旋转 90 度”错误。我在这里阅读了无数的帖子(StackOverFlow),并尝试了多种方法,但似乎无法修复它。
我仍然收到旋转不正确的图像。
在我的应用程序中,用户选择他/她的个人资料图片,然后将其设置为 ImageView。该图像选自电话图库
两天前,我实现了以下代码,这适用于我在手机上测试的所有图像。然而,当我的一位 Beta 测试人员尝试时,他的图像再次旋转。他向我发送了图像进行测试,但它们在我的手机上显示良好。这就是为什么我越来越沮丧。
这是我用来获取图像方向的方法:
// Gets an Images Orientation
public static int getOrientationEXIF(Context context, Uri uri) {
int orientation = 0;
try {
ExifInterface exif = new ExifInterface(uri.getPath());
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
orientation = 90;
return orientation;
case ExifInterface.ORIENTATION_ROTATE_180:
orientation = 180;
return orientation;
}
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
然后我使用此方法获得旋转位图:
// Rotate a Bitmap
public static Bitmap rotate(float rotationValue, String filePath) {
Bitmap original= BitmapFactory.decodeFile(filePath);
int width = original.getWidth();
int height = original.getHeight();
Matrix matrix = new Matrix();
matrix.postRotate(rotationValue);
Bitmap rotated = Bitmap.createBitmap(original, 0, 0, width, height, matrix, true);
return rotated;
}
我只是不知道该做什么了。
如果有人能帮我解决这个问题,我真的很高兴
先感谢您
UPDATE
实施建议的方法后,我刚刚在日志中看到以下代码行:
JHEAD can't open 'file:/external/images/media/3885'
我不确定这意味着什么
更新#2
我想我可能已经解决了问题,我得到了文件的正确图像路径。