Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code to copy one bitmap into another is like this:</p> <pre><code>Rect src = new Rect(0, 0, 50, 50); Rect dst = new Rect(50, 50, 200, 200); canvas.drawBitmap(originalBitmap, src, dst, null); </code></pre> <p>That specifies that you want to copy the top left corner (50x50) of a bitmap, and then stretch that into a 150x150 Bitmap and write it 50px offset from the top left corner of your canvas.</p> <p>You can trigger drawing via invalidate() but I recommend using a SurfaceView if you're doing animation. The problem with invalidate is that it only draws once the thread goes idle, so you can't use it in a loop - it would only draw the last frame. Here are some links to other questions I've answered about graphics, they might be of use to explain what I mean.</p> <ul> <li><a href="https://stackoverflow.com/questions/2539396/new-to-android-drawing-a-view-at-runtime/2539549#2539549">How to draw a rectangle</a> (empty or filled, and a few other options)</li> <li><a href="https://stackoverflow.com/questions/2554871/android-how-to-position-view-off-screen/2560731#2560731">How to create a custom SurfaceView for animation</a></li> <li><a href="https://stackoverflow.com/questions/2564171/view-animation-resizing-a-ball/2564483#2564483">Links to the code</a> for an app with randomly bouncing balls on the screen, also including touch control</li> <li><a href="https://stackoverflow.com/questions/2438733/how-to-do-animations-in-android-chess-game/2438763#2438763">Some more info</a> about SurfaceView versus Invalidate()</li> <li><a href="https://stackoverflow.com/questions/2439301/animating-and-rotating-an-image-in-a-surface-view/2439548#2439548">Some difficulties with manually rotating things</a></li> </ul> <hr> <p>In response to the comments, here is more information: If you get the Canvas from a SurfaceHolder.lockCanvas() then I don't think you can copy the residual data that was in it into a Bitmap. But that's not what that control is for - you only use than when you've sorted everything out and you're ready to draw.</p> <p>What you want to do is create a canvas that draws into a bitmap using</p> <pre><code>Canvas canvas = new Canvas(yourBitmap) </code></pre> <p>You can then do whatever transformations and drawing ops you want. yourBitmap will contain all the newest information. <em>Then</em> you use the surface holder like so:</p> <pre><code>Canvas someOtherCanvas = surfaceHolder.lockCanvas() someOtherCanvas.drawBitmap(yourBitmap, ....) </code></pre> <p>That way you've always got yourBitmap which has whatever information in it you're trying to preserve.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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