From fd88eed6f9e3b4f7e1b458f39e81eb6a1424fe1a Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 22 Jun 2019 14:49:02 +0200 Subject: [PATCH] Auto rotate received images --- .../main/java/eu/faircode/email/Helper.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index 40a1679fac..4486653d77 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -515,11 +515,26 @@ public class Helper { while (options.outWidth / factor > scaleToPixels) factor *= 2; - if (factor > 1) { + Matrix rotation = null; + try { + rotation = Helper.getImageRotation(file); + } catch (IOException ex) { + Log.w(ex); + } + + if (factor > 1 || rotation != null) { Log.i("Decode image factor=" + factor); options.inJustDecodeBounds = false; options.inSampleSize = factor; - return BitmapFactory.decodeFile(file.getAbsolutePath(), options); + Bitmap scaled = BitmapFactory.decodeFile(file.getAbsolutePath(), options); + + if (rotation != null) { + Bitmap rotated = Bitmap.createBitmap(scaled, 0, 0, scaled.getWidth(), scaled.getHeight(), rotation, true); + scaled.recycle(); + scaled = rotated; + } + + return scaled; } return BitmapFactory.decodeFile(file.getAbsolutePath());