java - 只有在三星手机图像从图库上传时才会旋转
问题描述
我正在尝试从我的应用程序上传图像,在尝试从相机或图库上传时,在所有其他设备上一切正常,但是当我尝试使用设备 samsung Galaxy J6 从图库->相机文件夹上传图像时,它得到在图像视图中旋转。当尝试从其他文件夹上传时,它工作正常,只有画廊内的相机文件夹出现此问题。我在谷歌上搜索得到了一些使用 exifinterface 的答案,但这也对我没有帮助。这没有在我的图像视图中显示所选图像,它正在执行 catch 块。请帮助我从过去两天卡住。
这是我的代码:-
if (requestCode == GALLERY) {
if (data != null) {
Uri contentURI = data.getData();
try {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), contentURI);
Bitmap converetdImage = getResizedBitmap(bitmap, 200);
PreferenceManager.saveStringForKey(myContext, AppConstant.PREFERENCE_TAG.IMAGE, AppConstant.getBase64Image(converetdImage));
Toast.makeText(myContext, "Image Saved!", Toast.LENGTH_SHORT).show();
/*ByteArrayOutputStream baos=new ByteArrayOutputStream();
byte [] b=baos.toByteArray();
String temp=Base64.encodeToString(b, Base64.DEFAULT);*/
ExifInterface exif = new ExifInterface(contentURI.toString());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Matrix matrix = new Matrix();
if (orientation == 6) {
matrix.postRotate(90);
}
else if (orientation == 3) {
matrix.postRotate(180);
}
else if (orientation == 8) {
matrix.postRotate(270);
}
Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
// imgProfile.setImageBitmap(bitmap);
imgProfile.setImageBitmap(rotatedBitmap);
is_image_change = true;
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(myContext, "Failed!", Toast.LENGTH_SHORT).show();
}
}
}
解决方案
推荐阅读
- django - 更新 Django 的 JSONField
- jenkins - junitreport failed 报告不会立即生成
- java - 清单合并失败:需要明确指定 android:exported
- javascript - 新输入不会更改子组件上的 FormGroup 禁用属性
- javascript - 将字符串转换为数组后,查找字符串中最长的单词
- c++ - 还有其他更强大的设置桌面背景图像的方法吗?
- python - Scoll 不适用于 IOS Appium 自动化
- reactjs - React中的垂直切换按钮组?
- angular - 离线添加数据AngularFire而不加载
- reactjs - axios get/post 无法访问 Fast API