Canvas clipping and region, Regioniterator

Source: Internet
Author: User

Mainly to look this article study: http://blog.csdn.net/lonelyroamer/article/details/8349601

Region.op parameters
    1. difference (0),  //final area region1  and   Region2 different area  
    2. intersect (1),  //  the final area is region1  with  region2;
    3. union (2),       // The final area is the area    of the region1  and  region2 combination;
    4. XOR (3),         //the final area is an area outside the region1 - region2 intersection   
    5. reverse_difference (4),  //the final area is region2  and  region1 different areas   
    6. REPLACE (5)  //the final area region2 for  
Canvas Cropping related methods:

1, the most basic cliprect, cutting a rectangle

2, Clippath, clipping path includes the scope, path includes the scope is not empty to be effective.

3, Clipregion.

 Public classCustomViewextendsView {Privatecontext Context; //brush variables, must be created    PrivatePaint paint; Privatepath Path;  PublicCustomView (Context context) {Super(context);  This. Context =context;    Initview (); }     PublicCustomView (context context, AttributeSet attrs,intdefstyleattr) {        Super(context, attrs, defstyleattr);  This. Context =context;    Initview (); }     PublicCustomView (Context context, AttributeSet attrs) {Super(context, attrs);  This. Context =context;    Initview (); }    Private voidInitview () {Paint=NewPaint (); //anti-aliasingPaint.setantialias (true); Paint.settextsize (6); //where to draw text//Paint.Align.CENTER//Paint.Align.LEFT//Paint.Align.LEFTpaint.settextalign (Paint.Align.RIGHT); Path=NewPath (); } @Overrideprotected voidOnDraw (canvas canvas) {Super. OnDraw (canvas); //Setting the canvas colorCanvas.drawcolor (Color.yellow); //Specific Explanation:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2013/0304/960.html        //Save : Used to save the state of the canvas.        After save, you can invoke canvas panning, indenting, rotating, trimming, cropping, and so on. //Restore : The state used to restore the canvas before it is saved. Preventing the actions that are performed on the canvas after save has an impact on subsequent drawing. Canvas.save (); //Canvas for horizontal movementCanvas.translate (10, 10);        Drawscene (canvas);        Canvas.restore (); //Start crop Operation//Save the canvas state firstCanvas.save (); Canvas.translate (160, 10); Canvas.cliprect (20, 20, 100, 100); //region, Chinese meaning is the meaning of an area, which represents a block of closed area on a canvas layer. //refer to http://blog.csdn.net/lonelyroamer/article/details/8349601//Region.Op.INTERSECT//Region.Op.REPLACE//Region.Op.REVERSE_DIFFERENCE//Region.Op.UNION//Region.Op.XOR//Region.Op.DIFFERENCECanvas.cliprect (40, 40, 80, 80, Region.Op.DIFFERENCE);    Drawscene (canvas); }    Private voiddrawscene (canvas canvas) {//Draw Rectangle 0,0 upper left corner, 100,100 lower right cornerCanvas.cliprect (0, 0, 100, 100); //Canvas color is whiteCanvas.drawcolor (Color.White); //Brush is redPaint.setcolor (color.red); //draw a line from the upper-left corner of the rectangle to the lower-right corner of the rectangleCanvas.drawline (0, 0, 100, 100, paint); //brush color is greenPaint.setcolor (Color.green); //Draw Circle, center Point, 30, 70, RadiusCanvas.drawcircle (30, 70, 30, paint); //Brush is bluePaint.setcolor (Color.Blue); //draw text, text coordinates 100,30Canvas.drawtext ("Clipping", 100, 30, paint); }}

Effect:

Not detailed, the back

Canvas clipping and region, Regioniterator

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.