Fixes a crash when reorienting and downsizing an image for upload. Closes #247
This commit is contained in:
parent
84b26d2b6b
commit
c8be990d1d
@ -86,7 +86,9 @@ class DownsizeImageTask extends AsyncTask<Uri, Void, Boolean> {
|
|||||||
try {
|
try {
|
||||||
Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
|
Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
|
||||||
bitmap.getHeight(), matrix, true);
|
bitmap.getHeight(), matrix, true);
|
||||||
|
if (!bitmap.sameAs(result)) {
|
||||||
bitmap.recycle();
|
bitmap.recycle();
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
return null;
|
return null;
|
||||||
@ -180,17 +182,21 @@ class DownsizeImageTask extends AsyncTask<Uri, Void, Boolean> {
|
|||||||
if (scaledBitmap == null) {
|
if (scaledBitmap == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
reorientBitmap(scaledBitmap, orientation);
|
Bitmap reorientedBitmap = reorientBitmap(scaledBitmap, orientation);
|
||||||
|
if (reorientedBitmap == null) {
|
||||||
|
scaledBitmap.recycle();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Bitmap.CompressFormat format;
|
Bitmap.CompressFormat format;
|
||||||
/* It's not likely the user will give transparent images over the upload limit, but
|
/* It's not likely the user will give transparent images over the upload limit, but
|
||||||
* if they do, make sure the transparency is retained. */
|
* if they do, make sure the transparency is retained. */
|
||||||
if (!scaledBitmap.hasAlpha()) {
|
if (!reorientedBitmap.hasAlpha()) {
|
||||||
format = Bitmap.CompressFormat.JPEG;
|
format = Bitmap.CompressFormat.JPEG;
|
||||||
} else {
|
} else {
|
||||||
format = Bitmap.CompressFormat.PNG;
|
format = Bitmap.CompressFormat.PNG;
|
||||||
}
|
}
|
||||||
scaledBitmap.compress(format, 75, stream);
|
reorientedBitmap.compress(format, 75, stream);
|
||||||
scaledBitmap.recycle();
|
reorientedBitmap.recycle();
|
||||||
scaledImageSize /= 2;
|
scaledImageSize /= 2;
|
||||||
iterations++;
|
iterations++;
|
||||||
} while (stream.size() > sizeLimit);
|
} while (stream.size() > sizeLimit);
|
||||||
|
Loading…
Reference in New Issue
Block a user