From 64dbb069abdb360a7b398c64daf022619b070693 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 29 Sep 2015 12:25:32 +0200 Subject: rotate thumbnails. fixes #1438 --- .../conversations/persistance/FileBackend.java | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index 817f1c51..f5549f92 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -260,6 +260,10 @@ public class FileBackend { } } + private int getRotation(File file) { + return getRotation(Uri.parse("file://"+file.getAbsolutePath())); + } + private int getRotation(Uri image) { InputStream is = null; try { @@ -274,8 +278,7 @@ public class FileBackend { public Bitmap getThumbnail(Message message, int size, boolean cacheOnly) throws FileNotFoundException { - Bitmap thumbnail = mXmppConnectionService.getBitmapCache().get( - message.getUuid()); + Bitmap thumbnail = mXmppConnectionService.getBitmapCache().get(message.getUuid()); if ((thumbnail == null) && (!cacheOnly)) { File file = getFile(message); BitmapFactory.Options options = new BitmapFactory.Options(); @@ -285,8 +288,12 @@ public class FileBackend { throw new FileNotFoundException(); } thumbnail = resize(fullsize, size); - this.mXmppConnectionService.getBitmapCache().put(message.getUuid(), - thumbnail); + fullsize.recycle(); + int rotation = getRotation(file); + if (rotation > 0) { + thumbnail = rotate(thumbnail, rotation); + } + this.mXmppConnectionService.getBitmapCache().put(message.getUuid(),thumbnail); } return thumbnail; } @@ -512,8 +519,10 @@ public class FileBackend { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(file.getAbsolutePath(), options); - int imageHeight = options.outHeight; - int imageWidth = options.outWidth; + int rotation = getRotation(file); + boolean rotated = rotation == 90 || rotation == 270; + int imageHeight = rotated ? options.outWidth : options.outHeight; + int imageWidth = rotated ? options.outHeight : options.outWidth; if (url == null) { message.setBody(Long.toString(file.getSize()) + '|' + imageWidth + '|' + imageHeight); } else { -- cgit v1.2.3