Android Drawing Common Methods Summary _android

Source: Internet
Author: User

What are the common methods of Android drawing, the following one by one for you to enumerate:

1, about the brush (Paint) method

Paint mpaint= new Paint ();
Mpaint.setantialias (TRUE); Anti-aliasing
mpaint.setstrokewidth (mcirclewidth);//Set the width of the ring
Mpaint.setstrokecap (Paint.Cap.ROUND); Defines a segment breakpoint shape as rounded head
Mpaint.setantialias (TRUE);//Anti-aliasing
Mpaint.setstyle (Paint.Style.STROKE);//Set Hollow 

Mpaint.descent ()//is the distance below baseline to the lowest point of the character
mpaint.ascent ()/is the distance above baseline to the top of the character

2, about the canvas (Canvas) method

How to create a new canvas

Create a canvas directly
Canvas Canvas = new Canvas (); 
Create a canvas with the specified Bitmap background
Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.ic_launcher);
Canvas canvas2 = new Canvas (bitmap); 

A summary of some common methods of drawing canvas

Used to save the state of canvas. Save, you can call the canvas translation, scaling, rotation, error-cut, cropping and other operations.
Canvas.save ();
The state to save before the canvas is restored. The actions performed against canvas after save have an effect on subsequent rendering.
//save and restore are paired with (restore can be less than save, but not many), and error is raised if the restore call is more than save.
Canvas.restore ();

Move the coordinate origin to the specified position
ccanvas.translate (x,y); 

Summary of common drawing methods

/** Draw arc, fan/
Canvas.drawarc (oval,//arc
    is the rectangle startangle,//the starting angle
    sweepangle,//rotation angle usecenter
    ,/ True to draw the pie, false is curved
    paint);//Brush 
/** Draw Text
/canvas.drawtext (text,//text content
    x, y,///Draw text start coordinates (upper left)
    paint);//Draw The brush of the text 
/** draw Line/
Canvas.drawline (startx, starty,//start xy coordinate
    stopx, stopy,//end XY coordinates 
    paint)//Draw a line with the brush
canvas.drawlines (pts,////the set of end points that draw the line, each line occupies 4 data.
    paint)//The drawing uses the brush
canvas.drawlines (pts,//the set of end points that draw the line, each line occupies 4 data.) The
    number of offset,//skipped data that will not participate in the drawing process.
    count,//The number of data actually involved in drawing.
    paint)//drawing 
/** Drawing Rectangle/
canvas.drawrect (float x1,float y1,//Draw Rectangle Upper-left corner vertex coordinates
    float x2,float y2,/ /Draw Rectangle Right corner vertex coordinate 
    Paint Paint);//Drawing brush

The above is the common method of the Android drawing, hope to be helpful to everybody's study.

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.