views:

233

answers:

0

I need to take a picture with the camera and, if depending on the picture size, rotate it before saving it into the gallery.

I'm using

Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE);

To take the pic and save it to a temporary file.

Then

Bitmap bmp = BitmapFactory.decodeFile(imagePath);
String str = android.provider.MediaStore.Images.Media.insertImage(cr, bmp, name, description);

To save it.

This is the code i have tried to use to rotate the bitmap

Matrix matrix = new Matrix();
matrix.postRotate(180);
Bitmap x = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
android.provider.MediaStore.Images.Media.insertImage(cr, x, name, description);

The problem is I'm getting an OutOfMemoryException.

Is there a better way to handle the bitmaps to avoid breaking the memory?

~Thanks in advance, regards