trying to deal with larger images
This commit is contained in:
parent
543d776986
commit
7f0efa089f
|
@ -94,17 +94,30 @@ public class FileBackend {
|
||||||
JingleFile file = getJingleFile(message);
|
JingleFile file = getJingleFile(message);
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
OutputStream os = new FileOutputStream(file);
|
Bitmap originalBitmap;
|
||||||
Bitmap originalBitmap = BitmapFactory.decodeStream(is);
|
try {
|
||||||
|
originalBitmap = BitmapFactory.decodeStream(is);
|
||||||
|
is.close();
|
||||||
|
} catch (OutOfMemoryError e) {
|
||||||
|
is.close();
|
||||||
|
Log.d("xmppService","catched out of memory. try again");
|
||||||
|
if (image != null) {
|
||||||
|
is = context.getContentResolver().openInputStream(image);
|
||||||
|
} else {
|
||||||
|
is = new FileInputStream(getIncomingFile());
|
||||||
|
}
|
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
options.inSampleSize = 2;
|
||||||
|
originalBitmap = BitmapFactory.decodeStream(is, null, options);
|
||||||
|
}
|
||||||
if (originalBitmap == null) {
|
if (originalBitmap == null) {
|
||||||
os.close();
|
|
||||||
throw new ImageCopyException(R.string.error_not_an_image_file);
|
throw new ImageCopyException(R.string.error_not_an_image_file);
|
||||||
}
|
}
|
||||||
is.close();
|
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
getIncomingFile().delete();
|
getIncomingFile().delete();
|
||||||
}
|
}
|
||||||
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
|
Bitmap scalledBitmap = resize(originalBitmap, IMAGE_SIZE);
|
||||||
|
OutputStream os = new FileOutputStream(file);
|
||||||
boolean success = scalledBitmap.compress(
|
boolean success = scalledBitmap.compress(
|
||||||
Bitmap.CompressFormat.WEBP, 75, os);
|
Bitmap.CompressFormat.WEBP, 75, os);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
|
Loading…
Reference in a new issue