0

I'm trying to reduce an Image resolution and to keep the same Image ratio, I'm just using the function create Scaled Bitmap.

Here is my code :

Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
        if (bitmap.getWidth() > 4096) bitmap = bitmap.createScaledBitmap(bitmap,bitmap.getWidth()/3,bitmap.getHeight()/3,true);
        if (bitmap.getHeight() > 4096) bitmap = bitmap.createScaledBitmap(bitmap,bitmap.getWidth()/3,bitmap.getHeight()/3,true);

Is there any way to make it better ?

Thanks

Stranger B.
  • 9,004
  • 21
  • 71
  • 108
  • See my answer here http://stackoverflow.com/a/32813456/746347 – mixel Oct 06 '15 at 21:53
  • Possible duplicate of [Setting view background causes OutOfMemoryError](http://stackoverflow.com/questions/32813248/setting-view-background-causes-outofmemoryerror) – mixel Oct 06 '15 at 21:54
  • you should do the calculation first, calculate the final dimensions and do only one resize. In your code the image could be resized twice – Christian Oct 06 '15 at 21:56

0 Answers0