3

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.

Bitmap/Canvas use and the NDK

Community
  • 1
  • 1
Neto Marin
  • 674
  • 3
  • 15
  • Have a look at http://stackoverflow.com/questions/11949234/androidissue-image-resolution/11949665#11949665. Hope it helps. – Braj Aug 20 '12 at 06:11
  • 1
    Unfortunately not. The option inSampleSize will return a smaller image, a subsample. I use this to create the preview image, but I want to crop from the full original image. – Neto Marin Aug 20 '12 at 06:17
  • That was the standard procedure to avoid OME I knew. Will get back to you if I find any other solution. – Braj Aug 20 '12 at 06:53

0 Answers0