I'm creating an edit photo app, and after the user selected a crop area in a scaled image preview, I want to crop a proportional area on the original image. To do this, I'm using the BitmapRegionDecoder, as follow:
InputStream in = mContentResolver.openInputStream(this.photoUri);
BitmapRegionDecoder regionDecoder = BitmapRegionDecoder.newInstance(in, false);
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = false;
//The following line causes an OutOfMemory
croppedBitmap = regionDecoder.decodeRegion(new Rect(x, y, destX, destY), o);
But I still getting an OutOfMemory exception. I'm thinking about reading small slices with the BitmapRegionDecoder and buffering it on a byte[], but I'm not sure if is it a good solution.
I think must have a better solution because I've already used other edition tools that crops large images. Any idea?
Thanks in advance, Neto.
* Possible solution !! * After talking to a lot of people, and after long hours of Internet searching, I found other question in Stackoverflow with a similar problem, and at this moment it seems to be te best way to solve this: using NDK.