From 78c085e6307e62398ac1f28596d3cb0586f9d726 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Wed, 28 Nov 2018 11:34:45 +0100 Subject: [PATCH] Improved BitmapWorkerTask to rotate and scale an image in one operation --- .../org/linphone/views/BitmapWorkerTask.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/linphone/views/BitmapWorkerTask.java b/app/src/main/java/org/linphone/views/BitmapWorkerTask.java index e4ce6ae28..9499693a3 100644 --- a/app/src/main/java/org/linphone/views/BitmapWorkerTask.java +++ b/app/src/main/java/org/linphone/views/BitmapWorkerTask.java @@ -86,16 +86,23 @@ public class BitmapWorkerTask extends AsyncTask { // Rotate the bitmap if possible/needed, using EXIF data Matrix matrix = new Matrix(); ExifInterface exif = new ExifInterface(path); + int width = bm.getWidth(); + int height = bm.getHeight(); + int pictureOrientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0); if (pictureOrientation == 6 || pictureOrientation == 3 || pictureOrientation == 8) { - if (pictureOrientation == 6) { - matrix.postRotate(90); - } else if (pictureOrientation == 3) { - matrix.postRotate(180); - } else { - matrix.postRotate(270); + if (imageView != null) { + float factor = (float) imageView.getMeasuredHeight() / height; + matrix.postScale(factor, factor); } - thumbnail = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true); + if (pictureOrientation == 6) { + matrix.preRotate(90); + } else if (pictureOrientation == 3) { + matrix.preRotate(180); + } else { + matrix.preRotate(270); + } + thumbnail = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true); if (thumbnail != bm) { bm.recycle(); bm = null;