diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-05-21 00:39:45 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-05-21 00:39:45 +0200 |
commit | 9d2ce5ff980d8469ee48efc25d645f2c9ca399c0 (patch) | |
tree | fe1410400329c25f7244f7e98f31cb292c027554 /src | |
parent | fa9cbeb746c8d065de8f6b55cb1d64cb683fa93a (diff) |
auto retry image compression with decreasing sample size
Diffstat (limited to 'src')
-rw-r--r-- | src/eu/siacs/conversations/persistance/FileBackend.java | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/eu/siacs/conversations/persistance/FileBackend.java b/src/eu/siacs/conversations/persistance/FileBackend.java index f76b079d..7bddc55f 100644 --- a/src/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/eu/siacs/conversations/persistance/FileBackend.java @@ -8,6 +8,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.bouncycastle.crypto.engines.ISAACEngine; + import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -81,8 +83,12 @@ public class FileBackend { return originalBitmap; } } + + public JingleFile copyImageToPrivateStorage(Message message, Uri image) throws ImageCopyException { + return this.copyImageToPrivateStorage(message, image,0); + } - public JingleFile copyImageToPrivateStorage(Message message, Uri image) + private JingleFile copyImageToPrivateStorage(Message message, Uri image, int sampleSize) throws ImageCopyException { try { InputStream is; @@ -95,22 +101,12 @@ public class FileBackend { file.getParentFile().mkdirs(); file.createNewFile(); Bitmap originalBitmap; - 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); - is.close(); - } + BitmapFactory.Options options = new BitmapFactory.Options(); + int inSampleSize = (int) Math.pow(2, sampleSize); + Log.d("xmppService","reading bitmap with sample size "+inSampleSize); + options.inSampleSize = inSampleSize; + originalBitmap = BitmapFactory.decodeStream(is, null, options); + is.close(); if (originalBitmap == null) { throw new ImageCopyException(R.string.error_not_an_image_file); } @@ -138,6 +134,8 @@ public class FileBackend { } catch (SecurityException e) { throw new ImageCopyException( R.string.error_security_exception_during_image_copy); + } catch (OutOfMemoryError e) { + return copyImageToPrivateStorage(message, image, sampleSize++); } } |