Buffer downloaded image data

pull/164/head
M66B 6 years ago
parent 16ff79ebe2
commit 6a94e8a5f9

@ -50,12 +50,12 @@ import androidx.core.graphics.ColorUtils;
import androidx.exifinterface.media.ExifInterface; import androidx.exifinterface.media.ExifInterface;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URL; import java.net.URL;
import java.security.MessageDigest; import java.security.MessageDigest;
@ -345,23 +345,22 @@ class ImageHelper {
return; return;
} }
BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bm;
try (BufferedInputStream is = new BufferedInputStream(new URL(a.source).openStream())) {
Log.i("Probe " + a.source); Log.i("Probe " + a.source);
try (InputStream probe = new URL(a.source).openStream()) { is.mark(8192);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(probe, null, options); BitmapFactory.decodeStream(is, null, options);
}
Log.i("Download " + a.source);
Bitmap bm;
try (InputStream is = new URL(a.source).openStream()) {
int scaleTo = res.getDisplayMetrics().widthPixels; int scaleTo = res.getDisplayMetrics().widthPixels;
int factor = 1; int factor = 1;
while (options.outWidth / factor > scaleTo) while (options.outWidth / factor > scaleTo)
factor *= 2; factor *= 2;
Log.i("Download " + a.source + " factor=" + factor);
is.reset();
if (factor > 1) { if (factor > 1) {
Log.i("Download image factor=" + factor);
options.inJustDecodeBounds = false; options.inJustDecodeBounds = false;
options.inSampleSize = factor; options.inSampleSize = factor;
bm = BitmapFactory.decodeStream(is, null, options); bm = BitmapFactory.decodeStream(is, null, options);

Loading…
Cancel
Save