diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-16 21:36:40 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-16 21:36:40 +0200 |
commit | c2bea6fe0e5d00db95a7c0b0eee68228d1fedab5 (patch) | |
tree | f10944cdffa9fa31acc1ed75857c626dfffbf7d5 /src/main/java/de/pixart | |
parent | 5ca356e4355c286a31a585481d49bd36e83cbfe4 (diff) |
don’t scale images to a 0 width or height
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 7ba41d8ad..17290864a 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -225,21 +225,23 @@ public class FileBackend { } - public Bitmap resize(Bitmap originalBitmap, int size) { + private Bitmap resize(final Bitmap originalBitmap, int size) throws IOException { int w = originalBitmap.getWidth(); int h = originalBitmap.getHeight(); - if (Math.max(w, h) > size) { + if (w <= 0 || h <= 0) { + throw new IOException("Decoded bitmap reported bounds smaller 0"); + } else if (Math.max(w, h) > size) { int scalledW; int scalledH; if (w <= h) { - scalledW = (int) (w / ((double) h / size)); + scalledW = Math.max((int) (w / ((double) h / size)), 1); scalledH = size; } else { scalledW = size; - scalledH = (int) (h / ((double) w / size)); + scalledH = Math.max((int) (h / ((double) w / size)), 1); } - Bitmap result = Bitmap.createScaledBitmap(originalBitmap, scalledW, scalledH, true); - if (originalBitmap != null && !originalBitmap.isRecycled()) { + final Bitmap result = Bitmap.createScaledBitmap(originalBitmap, scalledW, scalledH, true); + if (!originalBitmap.isRecycled()) { originalBitmap.recycle(); } return result; |