我正在拍摄照片并将其存储到SD卡中,然后将其从SD卡中查看到ImageView中,但获得轮换…
我在纵向模式下捕获它,但在横向模式下获得结果图像…
有什么我想念的吗?
在这里找到ExifUtil.java课程
/**
* Displaying captured image/video on the screen
* */
private void previewMedia(boolean isImage) {
// Checking whether captured media is image or video
if (isImage) {
imgPreview.setVisibility(View.VISIBLE);
final Bitmap bitmap = BitmapFactory.decodeFile(filePath);
Bitmap orientedBitmap = ExifUtil.rotateBitmap(filePath, bitmap);
imgPreview.setImageBitmap(orientedBitmap);
} else {
imgPreview.setVisibility(View.GONE);
}
}
但仍然在ImageView中显示旋转的图像…
解决方法:
您需要使用带有ORIENTATION_UNDEFINED的EXIF来获得正确的方向.
ExifInterface exif = null;
try {
exif = new ExifInterface(path);
} catch (IOException e) {
e.printStackTrace();
}
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);
并旋转位图:
Bitmap bmRotated = rotateBitmap(bitmap, orientation);