diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-08-31 16:17:04 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-08-31 16:17:04 +0000 |
commit | c39ea3c55fac807c0b98aabdf56c70dc8a49036c (patch) | |
tree | e282668a9587cf6c1ec7b604dea860400c75c6c7 /java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java | |
parent | 68038172793ee0e2ab3e2e56ddfbeb82879d1f58 (diff) | |
parent | 2ca4318cc1ee57dda907ba2069bd61d162b1baef (diff) |
Merge "Update Dialer source to latest internal Google revision."
Diffstat (limited to 'java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java')
-rw-r--r-- | java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java b/java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java index aeb8e0388..725cea723 100644 --- a/java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java +++ b/java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java @@ -21,6 +21,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; +import android.media.ExifInterface; import android.net.Uri; import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; @@ -47,17 +48,26 @@ class CopyAndResizeImageWorker implements Worker<Uri, Pair<File, String>> { } /** - * @param input The input Uri is expected to be a image openable by {@link - * android.content.ContentResolver#openInputStream(Uri)}. + * @param input The filepath where the image is located. * @return a Pair where the File contains the resized image, and the String is the result File's * MIME type. */ @Nullable @Override public Pair<File, String> doInBackground(@Nullable Uri input) throws Throwable { + // BitmapFactory.decodeStream strips exif data, so we need to save it here and apply it later. + int rotation = 0; + try { + rotation = + new ExifInterface(input.getPath()) + .getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); + } catch (Exception ignored) { + // Couldn't get exif tags, not the end of the world + } + try (InputStream inputStream = context.getContentResolver().openInputStream(input)) { Bitmap bitmap = BitmapFactory.decodeStream(inputStream); - bitmap = BitmapResizer.resizeForEnrichedCalling(bitmap); + bitmap = BitmapResizer.resizeForEnrichedCalling(bitmap, exifToDegrees(rotation)); File outputFile = DialerUtils.createShareableFile(context); try (OutputStream outputStream = new FileOutputStream(outputFile)) { @@ -67,4 +77,17 @@ class CopyAndResizeImageWorker implements Worker<Uri, Pair<File, String>> { } } } + + private static int exifToDegrees(int exifOrientation) { + switch (exifOrientation) { + case ExifInterface.ORIENTATION_ROTATE_90: + return 90; + case ExifInterface.ORIENTATION_ROTATE_180: + return 180; + case ExifInterface.ORIENTATION_ROTATE_270: + return 270; + default: + return 0; + } + } } |