title: Android Scaling Canvas Bitmap
body: <p>I have a drawing app that allows the user to draw to a blank canvas.  I am attempting to draw a scaled 'thumbnail' of the current bitmap so that when the user has scaled in the View, they can reference the thumbnail to get a sense as to where they are in the overall draw canvas.  I have the scaling working, and am displaying the thumbnail in the correct location, but it appears that the thumbnail is not being updated on subsequent onDraws when new lines/shapes are added.</p>
  
  <p>So that I have access to the underlying bitmap for this view (to show the thumbnail, be able to easily save the bitmap to a file, etc) I do the following in onSizeChanged() for the View:</p>
  
  <pre><code>@Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
      super.onSizeChanged(w, h, oldw, oldh);
  
      // set the canvas height, panning, etc, based on the now inflated View
      mWidth      = getWidth();
      mHeight     = getHeight();
      mAspectRatio    = mWidth / mHeight;
      mPanX       = 0;
      mPanY       = 0;
  
      // create the Bitmap, set it to the canvas
  mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
  mCanvas.setBitmap(mBitmap);
  draw(mCanvas);
  }
  </code></pre>
  
  <p>Then, when the user draws and invalidate() is called, I do the following in onDraw() to generate the thumbnail:</p>
  
  <pre><code>@Override
  protected void onDraw(Canvas canvas) {
      &lt;snipped code that draws paths, shapes to canvas&gt;
  
      if (mScaled) {
          Bitmap out = Bitmap.createScaledBitmap(mBitmap, (int) thumbWidth, (int) thumbHeight, false);
          canvas.drawBitmap(out, null, thumbnailRectF, thumbCanvasPaint);
      }
  }
  </code></pre>
  
  <p>The thumbnail gets displayed in the space defined by thumbnailRectF using the thumbCanvasPaint, but in subsequent onDraw() calls, the scaled bitmap has not changed from it's original state, even though the full-sized active canvas shows all of the drawings, etc.  Based on some testing, it seems to me that while I am setting the Bitmap with the initial call to draw(mCanvas);, subsequent onDraws are writing to the underlying Bitmap rather than the one specified in onSizeChanged().</p>
  
  <p>So, I guess I am trying to figure out how I tie the onDraw canvas to a Bitmap that I can readliy access to perform re-sizes, save, etc.  Looking at <a href="https://stackoverflow.com/questions/2174875/android-canvas-to-jpg">this question</a>, I thought that the draw(mCanvas); call would tie the onDraw to the bitmap specified in the mCanvas (in my case, mBitmap), but in practice, it doesn't seem to be working, in so far as updats to the canvas are concerned.</p>
  
  <p>Thanks,</p>
  
  <p>Paul</p>