Android Canvas drawing operation of the cutting Canvas implementation method (Cliprect) _android

Source: Internet
Author: User

This paper illustrates the method of cutting canvas for Android Canvas drawing operation. Share to everyone for your reference, specific as follows:

Android is not difficult to cut the canvas, but it is also more trouble to understand, here to write my understanding but not necessarily correct:

Canvas.cliprect (n, Region.Op.XOR);

The last parameter has more than one selection:

Difference is the first time different from the second part of the show
Replace is displayed for the second time
Reverse_difference is the second time different from the first part of the show
Intersect intersection display
UNION ALL Show
XOR complement is the complete set minus the intersection of the reproductive part of the show

Import Android.content.Context;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import Android.graphics.Path;
Import android.graphics.Region;
Import Android.util.AttributeSet;
Import Android.view.View;
  public class Sbook extends view{context Mcontext;
  Paint Mpaint;
  Path MPath;
    Public Sbook {Super (context);
  Init ();
    Public Sbook (context, AttributeSet attrs) {Super (context, attrs);
  Init ();
    Public Sbook (context, AttributeSet attrs, int defstyle) {Super (context, attrs, Defstyle);
  Init ();
    private void Init () {mpaint = new Paint ();
    Mpaint.setantialias (TRUE);
    Mpaint.setstrokewidth (6);
    Mpaint.settextsize (16);
    Mpaint.settextalign (Paint.Align.RIGHT);
  MPath = new Path ();
    } protected void OnDraw (Canvas Canvas) {canvas.drawcolor (Color.gray);
    Canvas.save ();
    Canvas.translate (10, 10);
    Drawscene (canvas);
  Canvas.restore ();  Canvas.save ();
    Canvas.translate (160, 10);
    Canvas.cliprect (10, 10, 90, 90);
    Canvas.cliprect (n, Region.Op.XOR);
    Drawscene (canvas);
    Canvas.restore ();
    Canvas.save ();
    Canvas.translate (10, 160);
Mpath.reset (); Canvas.clippath (MPath);
    Makes the clip empty//Mpath.addcircle (M, Path.Direction.CCW);
    Mpath.cubicto (0, 0, 100, 0, 100, 100);
    Mpath.cubicto (100, 100, 0, 100, 0, 0);
    Canvas.clippath (MPath, Region.Op.REPLACE);
    Drawscene (canvas);
    Canvas.restore ();
    Canvas.save ();
    Canvas.translate (160, 160);
    Canvas.cliprect (0, 0, 60, 60);
    Canvas.cliprect (A, n, Region.Op.UNION);
    Drawscene (canvas);
    Canvas.restore ();
    Canvas.save ();
    Canvas.translate (10, 310);
    Canvas.cliprect (0, 0, 60, 60);
    Canvas.cliprect (A, n, Region.Op.XOR);
    Drawscene (canvas);
    Canvas.restore ();
    Canvas.save ();
    Canvas.translate (160, 310);
    Canvas.cliprect (0, 0, 60, 60); CAnvas.cliprect (A, n, Region.Op.REVERSE_DIFFERENCE);
    Drawscene (canvas);
  Canvas.restore ();
    } private void Drawscene (Canvas Canvas) {canvas.cliprect (0, 0, 100, 100);
    Canvas.drawcolor (Color.White);
    Mpaint.setcolor (color.red);
    Canvas.drawline (0, 0, N, mpaint);
    Mpaint.setcolor (Color.green);
    Canvas.drawcircle (Mpaint);
    Mpaint.setcolor (Color.Blue);
  Canvas.drawtext ("Clipping", M, Mpaint);

 }
}

For more information on Android-related content readers can view the site: "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

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.