Miscellaneous language: See a lot of programs ape have to write the habit of blogging, it seems I have to practice, no matter how good the writing, learn a little experience to write it.
Content Commentary : These days began to learn game map production, today a small summary of the use of Canvas cliprect () interface.
1 Select the area you want to draw (refresh) on the canvas, as shown in (x, y) as the starting point, wide W, high H
2 Select the picture that you want to draw, not necessarily is just width high for (w,h), the big picture needs to cut (this example draws green area)
3 draw the picture to the canvas so that the green area coincides with the white square
4) Final Effect chart
Code Commentary :
Copy Code code as follows:
Canvas.save ();
Canvas.cliprect (x1, y1, x1 + W, y1 + h);
Canvas.drawbitmap (Bitmap, x2, y2, paint);
Canvas.restore ();
1, Save () first the canvas data to save (such as matrix, etc.), the final draw after the restore () then the middle of the canvas coordinates and other operations forget off;
2, Cliprect () to intercept an area of the canvas;
3, Drawbitmap () draw the picture to (x2, y2), the green part is just drawn to (x1, y1), and the area without being clip will not draw;
4. Restore () Finally, revert the canvas to the original data (remember that Save () is paired with Restore ()).
5, small code, a lot of nonsense