fix media resizing (#686)
* fix media resizing * move exception catching out of method
This commit is contained in:
parent
63f9d99390
commit
a42ce9b793
3 changed files with 26 additions and 9 deletions
|
|
@ -172,7 +172,6 @@ public class DownsizeImageTask extends AsyncTask<Uri, Void, Boolean> {
|
|||
* test, and keep trying at smaller sizes. The initial estimate should be good for
|
||||
* many cases, so it should only iterate once, but the loop is used to be absolutely
|
||||
* sure it gets downsized to below the limit. */
|
||||
int iterations = 0;
|
||||
int scaledImageSize = 1024;
|
||||
do {
|
||||
stream.reset();
|
||||
|
|
@ -208,12 +207,11 @@ public class DownsizeImageTask extends AsyncTask<Uri, Void, Boolean> {
|
|||
} else {
|
||||
format = Bitmap.CompressFormat.PNG;
|
||||
}
|
||||
reorientedBitmap.compress(format, 75, stream);
|
||||
reorientedBitmap.compress(format, 85, stream);
|
||||
reorientedBitmap.recycle();
|
||||
scaledImageSize /= 2;
|
||||
iterations++;
|
||||
} while (stream.size() > sizeLimit);
|
||||
Assert.expect(iterations < 3);
|
||||
|
||||
resultList.add(stream.toByteArray());
|
||||
if (isCancelled()) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -126,4 +126,17 @@ public class MediaUtils {
|
|||
source.recycle();
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public static long getImageSquarePixels(ContentResolver contentResolver, Uri uri) throws FileNotFoundException {
|
||||
InputStream input;
|
||||
input = contentResolver.openInputStream(uri);
|
||||
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeStream(input, null, options);
|
||||
|
||||
IOUtils.closeQuietly(input);
|
||||
|
||||
return (long) options.outWidth * options.outHeight;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue