title: How to work with large bitmap. Rotating and inserting to the gallery
body: <p>I need to take a picture with the camera and, if depending on the picture size, rotate it before saving it into the gallery.</p>
  
  <p>I'm using </p>
  
  <blockquote>
    <p>Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
       startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE);</p>
  </blockquote>
  
  <p>To take the pic and save it to a temporary file.</p>
  
  <p>Then </p>
  
  <blockquote>
    <p>Bitmap bmp = BitmapFactory.decodeFile(imagePath);<br>
       String str = android.provider.MediaStore.Images.Media.insertImage(cr, bmp, name, description);</p>
  </blockquote>
  
  <p>To save it.</p>
  
  <p>This is the code i have tried to use to rotate the bitmap</p>
  
  <blockquote>
    <p>Matrix matrix = new Matrix();<br>
       matrix.postRotate(180);<br>
       Bitmap x = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix,    true);<br>
       android.provider.MediaStore.Images.Media.insertImage(cr, x, name, description);  </p>
  </blockquote>
  
  <p>The problem is I'm getting an OutOfMemoryException.</p>
  
  <p>Is there a better way to handle the bitmaps to avoid breaking the memory?</p>
  
  <p>~Thanks in advance, regards</p>