我正在拍照并将其存储到SD Card中,然后再从SD Card中将其查看到ImageView中,但是旋转得很...

我正在Portrait mode中捕获它,但是在Landscape mode中得到了合成图像...

有什么我想念的吗?

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中显示旋转的图像...

最佳答案

您需要使用EXIF ORIENTATION_UNDEFINED 来获得正确的方向。

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);

Reference link

10-07 15:41