0

I'm cropping midi-resolution images in Android (doing a crop). One of the customers requirement is to do a 'Best Effort' in that.

I'm using
croppedImage = decoder.decodeRegion(rect, o);

Where o is my BitmapFactory.Options. This line sometimes is launching an

'External allocation too large for this process /VM won't let us allocate XXXXXXX bytes' sometimes when I'm using as a PreferredConfig a Config.ARGB_8888'

I'm trying to catch that in order to retry cropping with Config.RGB565, that never has memory problem, but changes the color profile of the image.

How could I catch this (I've already tried by catching any Throwable object). If that is not possible I would like to pre-suposse memory problems and decodeRegion with RGB_565 directly, but I don't know how to do that.

pozuelog
  • 1,284
  • 13
  • 27
  • Why dont you just make the rects smaller? Try dividing your original rect into sub-rects of a more manageable size. – Mister Smith May 13 '14 at 09:34
  • You can also try adding the [largeHeap](http://developer.android.com/guide/topics/manifest/application-element.html#largeHeap) flag to the manifest. – Mister Smith May 13 '14 at 09:37
  • I've already added largeHeap! I thing a can make rects smaller by dividing images into sub-rects, but after that I'll have same problems while joining images. – pozuelog May 13 '14 at 09:40
  • Yeah, you are right. Maybe you could work in reducing the image to a more mobile-friendly resolution. And also have a look at these questions: http://stackoverflow.com/questions/10001706/getting-error-external-allocation-too-large-for-this-process, http://stackoverflow.com/questions/17383677/android-exception-external-allocation-too-large-for-this-process, http://stackoverflow.com/questions/7493095/android-external-allocation-too-large-but-why – Mister Smith May 13 '14 at 09:46
  • I thing I've already add largeHeap into the manifest. – pozuelog May 13 '14 at 09:58
  • Problem is that I need a printable image. What about predict memory issues (by measuring it and calculating bitmap image with ARGB_888), and launch decoding with RGB565? – pozuelog May 13 '14 at 10:00

0 Answers0