diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-09-29 12:25:32 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-09-29 12:25:32 +0200 |
commit | 64dbb069abdb360a7b398c64daf022619b070693 (patch) | |
tree | cbf6ebe8ff232af717b31f4bcb565fadb7795f01 /src | |
parent | 5fb77a9739912c9a418b91cb2acfe54c3c88825d (diff) |
rotate thumbnails. fixes #1438
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 21 |
1 files changed, 15 insertions, 6 deletions
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 { |