title: Android Image from camera saved with overlay
body: <p>I've tried several different ways to get this to work but have come to a halt. I'm getting a photo from the camera and saving it with an overlay.</p>
  
  <p>To combine the images, I have worked out how to do so with two bitmaps and a canvas like so:</p>
  
  <pre><code>   Bitmap combined = Bitmap.createBitmap(mImage.getWidth(), mImage.getHeight(), null);
     Canvas canvas = new Canvas(combined);
  
     canvas.drawBitmap(image, new Matrix(), null);
     canvas.drawBitmap(mOverlay, 0,0,null);
  
     output = new FileOutputStream(new File(mFile.getPath(), mFileName + "(overlay).jpg" ));
     output.write(bytes);
     output.close();
  </code></pre>
  
  <p>The issue is I'm using camera2, which returns an Image. I haven't worked out a way to cast an Image to a Bitmap. I've tried saving the image and then reloading it using BitmapFactory, but frequently end up with OutOfMemory Exceptions.</p>
  
  <p>Has anybody got a way they go around this?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    Bitmap image = Bitmap.createBitmap(mImage.getWidth(),mImage.getHeight(), Bitmap.Config.ARGB_8888);
      image.copyPixelsFromBuffer(mImage.getPlanes()[0].getBuffer().rewind());
  </code></pre>
  
  <p>I stumbled across this in another answer, but I am getting a <code>Buffer not large enough for pixels</code> exception, even when I have specified a buffer up to 8x larger than should have been necessary.</p>