diff options
author | Eric Erfanian <erfanian@google.com> | 2017-06-22 21:24:13 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-06-22 21:24:13 +0000 |
commit | 7b6472711e15ba90d54b3ccc7cc867e226938565 (patch) | |
tree | 742285fa641f62ba0b358a65a452f4f65db04ce2 /java/com/android/dialer/callcomposer/CopyAndResizeImageWorker.java | |
parent | f43ad4c585ad1426f23021c358795eb9ae8eccf1 (diff) | |
parent | 842a9777de13bebb1c82f9d57222c52f9ddec558 (diff) |
Update AOSP Dialer source from internal google3 repository at cl/159771812.
am: 842a9777de
Change-Id: Ib1d6495d08196f047aacb3f26cab28d20542ff3b
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; + } + } } |