Android Image Rendering (vii) Cliprect local drawing/cutting artwork summary _android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.