summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorByteHamster <info@bytehamster.com>2021-10-05 20:53:29 +0200
committerByteHamster <info@bytehamster.com>2021-10-05 20:53:29 +0200
commitc742b2b8ca60be15ab8ede6cd2e6e72f3c4ab678 (patch)
treecd3a042e401b0b7ce75f2c83f30d6dade230974f
parent160401ad13778e9f611fde864910e55339a3f921 (diff)
downloadAntennaPod-c742b2b8ca60be15ab8ede6cd2e6e72f3c4ab678.zip
Trying to make image resizing more stable
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java10
1 files changed, 7 insertions, 3 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java b/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java
index 7b8eed6e0..11e2f944e 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/glide/ResizingOkHttpStreamFetcher.java
@@ -17,12 +17,13 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class ResizingOkHttpStreamFetcher extends OkHttpStreamFetcher {
private static final String TAG = "ResizingOkHttpStreamFetcher";
- private static final int MAX_DIMENSIONS = 2000;
+ private static final int MAX_DIMENSIONS = 1500;
private static final int MAX_FILE_SIZE = 1024 * 1024; // 1 MB
private FileInputStream stream;
@@ -66,7 +67,9 @@ public class ResizingOkHttpStreamFetcher extends OkHttpStreamFetcher {
BitmapFactory.decodeStream(in, null, options);
IOUtils.closeQuietly(in);
- if (Math.max(options.outHeight, options.outWidth) >= MAX_DIMENSIONS) {
+ if (options.outWidth == -1 || options.outHeight == -1) {
+ throw new IOException("Not a valid image");
+ } else if (Math.max(options.outHeight, options.outWidth) >= MAX_DIMENSIONS) {
double sampleSize = (double) Math.max(options.outHeight, options.outWidth) / MAX_DIMENSIONS;
options.inSampleSize = (int) Math.pow(2d, Math.floor(Math.log(sampleSize) / Math.log(2d)));
}
@@ -97,12 +100,13 @@ public class ResizingOkHttpStreamFetcher extends OkHttpStreamFetcher {
break;
}
}
+ bitmap.recycle();
stream = new FileInputStream(tempOut);
callback.onDataReady(stream);
Log.d(TAG, "Compressed image from " + tempIn.length() / 1024
+ " to " + tempOut.length() / 1024 + " kB (quality: " + quality + "%)");
- } catch (Exception e) {
+ } catch (Throwable e) {
e.printStackTrace();
try {