Android Image Rendering (7) cliprect local drawing/cutting source drawing Summary

Source: Internet
Author: User

Miscellaneous: read a lotProgramYuandu has the habit of writing a blog. It seems that I have to practice it too. No matter what the writing is, write it if you have learned something.

Content Description: I have been learning how to create game maps over the past few days. Today I will briefly summarize the use of the canvas cliprect () interface.

1) Select the area where you want to draw (refresh) on the canvas, with (x, y) as the starting coordinate, width W, and height H.

2) Select the image to be drawn, not necessarily the width and height (W, h). You need to cut the large image (in this example, the green area is drawn)

3) draw an image on the canvas to make the green area overlap with the white block.

4) Last

CodeExplanation:

Copy codeThe Code is as follows: canvas. Save ();
Canvas. cliprect (x1, Y1, X1 + W, Y1 + H );
Canvas. drawbitmap (bitmap, X2, Y2, paint );
Canvas. Restore ();

1. Save () first saves the canvas data (such as matrix), and then restore () after the painting is complete. Then, forget is performed on the canvas coordinates in the middle;
2. cliprect () captures an area in the canvas;
3. When drawbitmap () is used to draw an image on (X2, Y2), the green part is drawn on (x1, Y1), but not on the clip area;
4. At last, restore () needs to restore the canvas to the original data (remember to pair save () with restore ).
5. Little code, a lot of nonsense

Related Article

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.