我在画廊图像旋转方面遇到一些问题。我已经在网上搜索过,并且尝试使用ExifInterface
解决它们。该解决方案可能有效,但我无法确定设置图像位图时该应用程序未显示任何内容。
我也尝试将位图转换为uri,但应用程序崩溃了。
@Override
protected void onActivityResult(int requestCode , int resultCode , Intent data) {
if (requestCode == PICK_IMAGE && resultCode == RESULT_OK) {
imageuri = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(imageuri, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
loadedBitmap = BitmapFactory.decodeFile(picturePath);
ExifInterface exif = null;
try {
File pictureFile = new File(picturePath);
exif = new ExifInterface(pictureFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
int orientation = ExifInterface.ORIENTATION_NORMAL;
if (exif != null)
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
loadedBitmap = rotateBitmap(loadedBitmap, 90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
loadedBitmap = rotateBitmap(loadedBitmap, 180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
loadedBitmap = rotateBitmap(loadedBitmap, 270);
break;
default:
}
photo.setImageBitmap(loadedBitmap);
immagineview.setImageBitmap(loadedBitmap);