title: Android createBitmap in onDraw method
body: <p>I know it is not recommended to create any object during <code>onDraw()</code> method so I am looking for another way how to solve this. Let's say I have a camera stream, then I do some object detection using OpenCV library inside <code>onPreviewFrame()</code>.</p>
  
  <p>During <code>onDraw()</code> method I need to iterate over all the detected objects, crop them from the input image and scale each one of them and then draw this cropped bitmap on the original bitmap.</p>
  
  <p>My current solution requires 2 bitmaps - one is the original, the other one is used for drawing (I don't draw on the original because there could happen that I would crop something from the part of image where the new objects was already drawn).</p>
  
  <pre><code>@Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
  
    canvasTmp.setBitmap(mBitmap);
  
    for (Object o:objects) {
      Bitmap croppedBmp = Bitmap.createBitmap(mBitmapCopy, area_to_crop...);
      croppedBmp Bitmap.createScaledBitmap(croppedBmp , new_size...);
      canvasTmp.drawBitmap(croppedBmp, new_position)
    }
  
    canvas.drawBitmap(mBitmap, 0, 0, bitmapPaint);    
  }
  </code></pre>
  
  <p>Creating <code>mBitmap</code> and <code>mBitmapCopy</code> isn't so expensive operation as I am using <code>setPixels()</code> method but I was wondering if there is any way how to get rid of recreating bitmap on each iteration?</p>
  
  <p>Thanks</p>