Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Copying a bitmap
    primarykey
    data
    text
    <p>A seemingly simple issue, I have an off-screen bitmap that I perform some transformations to (rotation, scaling, etc) and I'd like to store a copy of the bitmap prior to the transformations, such that in my View's <code>onDraw()</code>, I can display the transformed off-screen bitmap AND a smaller scaled version of the un-transformed bitmap as a thumbnail.</p> <p>No problem writing the off-screen bitmap in <code>onDraw()</code>, but the copied 'preserved' bitmap is also being transformed. Here is the code where I am making the copy of the bitmap, where mCanvas was created via <code>mCanvas = new Canvas(mBitmap);</code>:</p> <pre><code>mPreservedBitmap = Bitmap.createBitmap(mBitmap); // save the canvas mCanvas.save(); // do some rotations, scaling mCanvas.rotate(rotation, px, py); mCanvas.scale(scaleFactor, scaleFactor, scaleFocusX, scaleFocusY); // draw the bitmaps to the screen invalidate(); // restore the bitmap mCanvas.restore(); </code></pre> <p>In <code>onDraw()</code>, I have:</p> <pre><code>// draw the off-screen bitmap to the on-screen bitmap canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); // draw the preserved image, scaling it to a thumbnail first canvas.drawBitmap( Bitmap.createScaledBitmap(mPreservedBitmap, (int) thumbWidth, (int) thumbHeight, true), null, thumbnailRectF, thumbCanvasPaint); </code></pre> <p>The thumbnail gets scaled to the appropriate size, but the bitmap that is being scaled down to thumbnail size is also rotated and scaled the exact same as mBitmap, which I don't want. I've also tried the Bitmap.copy() method, but with the same results. Any pointers/assitance/advice?</p> <p>Thanks,</p> <p>Paul</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload