Merge "Fix thumbnail's orienation issue" into qt-dev
This commit is contained in:
@@ -36,7 +36,6 @@ import android.graphics.Bitmap;
|
|||||||
import android.graphics.ImageDecoder;
|
import android.graphics.ImageDecoder;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.media.ExifInterface;
|
import android.media.ExifInterface;
|
||||||
import android.media.MediaFile;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -1681,11 +1680,13 @@ public final class DocumentsContract {
|
|||||||
public static AssetFileDescriptor openImageThumbnail(File file) throws FileNotFoundException {
|
public static AssetFileDescriptor openImageThumbnail(File file) throws FileNotFoundException {
|
||||||
final ParcelFileDescriptor pfd = ParcelFileDescriptor.open(
|
final ParcelFileDescriptor pfd = ParcelFileDescriptor.open(
|
||||||
file, ParcelFileDescriptor.MODE_READ_ONLY);
|
file, ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
Bundle extras = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final ExifInterface exif = new ExifInterface(file.getAbsolutePath());
|
final ExifInterface exif = new ExifInterface(file.getAbsolutePath());
|
||||||
|
|
||||||
|
final long[] thumb = exif.getThumbnailRange();
|
||||||
|
if (thumb != null) {
|
||||||
|
// If we use thumb to decode, we need to handle the rotation by ourselves.
|
||||||
|
Bundle extras = null;
|
||||||
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) {
|
switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) {
|
||||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||||
extras = new Bundle(1);
|
extras = new Bundle(1);
|
||||||
@@ -1701,26 +1702,13 @@ public final class DocumentsContract {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
final long[] thumb = exif.getThumbnailRange();
|
|
||||||
if (thumb != null) {
|
|
||||||
return new AssetFileDescriptor(pfd, thumb[0], thumb[1], extras);
|
return new AssetFileDescriptor(pfd, thumb[0], thumb[1], extras);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use ImageDecoder to do full image decode of heif format file
|
// Do full file decoding, we don't need to handle the orientation
|
||||||
// will have right orientation. So, we don't need to add orientation
|
return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, null);
|
||||||
// information into extras.
|
|
||||||
final String mimeType = MediaFile.getMimeTypeForFile(file.getName());
|
|
||||||
if (mimeType.equals("image/heif")
|
|
||||||
|| mimeType.equals("image/heif-sequence")
|
|
||||||
|| mimeType.equals("image/heic")
|
|
||||||
|| mimeType.equals("image/heic-sequence")) {
|
|
||||||
return new AssetFileDescriptor(pfd, 0 /* startOffset */,
|
|
||||||
AssetFileDescriptor.UNKNOWN_LENGTH, null /* extras */);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, extras);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void rethrowIfNecessary(Exception e) throws FileNotFoundException {
|
private static void rethrowIfNecessary(Exception e) throws FileNotFoundException {
|
||||||
|
|||||||
@@ -265,13 +265,10 @@ public class ThumbnailUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHeifFile = false;
|
|
||||||
|
|
||||||
if (mimeType.equals("image/heif")
|
if (mimeType.equals("image/heif")
|
||||||
|| mimeType.equals("image/heif-sequence")
|
|| mimeType.equals("image/heif-sequence")
|
||||||
|| mimeType.equals("image/heic")
|
|| mimeType.equals("image/heic")
|
||||||
|| mimeType.equals("image/heic-sequence")) {
|
|| mimeType.equals("image/heic-sequence")) {
|
||||||
isHeifFile = true;
|
|
||||||
try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) {
|
try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) {
|
||||||
retriever.setDataSource(file.getAbsolutePath());
|
retriever.setDataSource(file.getAbsolutePath());
|
||||||
bitmap = retriever.getThumbnailImageAtIndex(-1,
|
bitmap = retriever.getThumbnailImageAtIndex(-1,
|
||||||
@@ -298,12 +295,9 @@ public class ThumbnailUtils {
|
|||||||
|
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(file), resizer);
|
bitmap = ImageDecoder.decodeBitmap(ImageDecoder.createSource(file), resizer);
|
||||||
// Use ImageDecoder to do full image decode of heif format file
|
// Use ImageDecoder to do full file decoding, we don't need to handle the orientation
|
||||||
// will have right orientation. Don't rotate the bitmap again.
|
|
||||||
if (isHeifFile) {
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Transform the bitmap if the orientation of the image is not 0.
|
// Transform the bitmap if the orientation of the image is not 0.
|
||||||
if (orientation != 0 && bitmap != null) {
|
if (orientation != 0 && bitmap != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user