A summary of the methods of the Paint and Canvas classes in Android, canvas in Android

Source: Internet
Author: User
Tags drawtext

A summary of the methods of the Paint and Canvas classes in Android, canvas in Android

Common Methods of the Paint class


1. The setColor method is used to set the color of the paint brush,
Public void setColor (int color) // The color parameter is the Color value. You can also use the color defined by the color class.
Color. BLACK: BLACK
Color. BLUE: BLUE
Color. CYAN: Green
Color. DKGRAY: Gray-black
Color. YELLOW: YELLOW
Color. GRAY: GRAY
Color. GREEN: GREEN
Color. LTGRAY: light green
Color. MAGENTA: red and purple
Color. TRANSPARENT: TRANSPARENT


2. The setAlpha method is used to set the transparency of the paint brush.
Public void setAlpha (int a) // parameter a is transparency, and its value range is 0 ~ 255, the smaller the value, the more transparent


3. The setStyle method is used to set the paint brush style. It can be used to specify the center or solid. This method has obvious effect on the rectangle and circle.
Public void setStyle (Paint. Style style) // The style parameter is the Paint Style.
Style. FILL: Solid
Style. FILL_AND_STROKE: both solid and hollow are displayed.
Style. STROKE: hollow


4. The setStrokeWidth method is used to set the hollow width of the paint brush. This method has obvious effects on rectangles, circles, and other images.
Public void setStrokeWidth (float width) // The parameter width is the width of the float data.


5. The setTextSize method is used to set the font size of the paint brush. It is mainly used to draw strings.
Public void setTextSize (float textSize )//


6. The setTypeface method is used to set the font style of the paint brush. You can use the built-in fields or custom fonts.
Public void Typeface (Typeface typeface) // typeface indicates the font style.
Typeface. DEFAULT: DEFAULT font
Typeface. DEFAULT_BOLD: bold font
Typeface. MONOSPACE: monospace font
Typeface. SANS_SERIF: sans font
Typeface. SERIF: serif font


7. setTextScaleX method. Used to set the ratio of the paint brush font. The default value is 1. If it is greater than 1, it indicates horizontal scaling. If it is smaller than 1, it indicates horizontal compression.
Public void setTextScaleX (float scaleX)


8. setARGB method, used to set the color and transparency of the paint brush
Public void setARGB (int a, int r, int g, int B );
Parameter a is transparency and the value range is 0 ~ 255
The value of the r parameter is a red color value in the range of 0 ~ 255
The parameter g is a green color value in the range of 0 ~ 255
Parameter B is a blue color value in the range of 0 ~ 255


9. setUnderlineText method, used to set the underline Of the paint brush
Public void setUnderlineText (Boolean underlintext)
If the value is true, the underline is displayed.


10. setTextSkewX method, used to set the tilt factor of the paint brush
Public void setTextSkewX (float skewX)
The skewX parameter is a skew factor. A positive value indicates tilting to the left, and a negative value indicates tilting to the right.

 


Canvas Class Method


1. public void drawColor (int color)
Used to set the background color of the canvas.


2. public void drawLine (float starX, float startY, float stopX, float stopY, painting );
Used to draw a straight line on the canvas
The parameters are the X, Y, and Y coordinates of the starting point of the straight line, respectively.


3. public void drawLines (float [] pts, Paint paint)
Used to draw multiple straight lines on the canvas
The pts parameter is the endpoint array for drawing a straight line. Each line occupies 4 data records.


4. public void drawPoint (float x, float y, Paint paint)
Used to draw points on the canvas
The parameter is the X, Y coordinates of the vertex, And the paint brush used.


5. public void drawPoints (float [] pts, Paint paint)
Public void drawPoints (float [] pts, int offset, int count, Paint paint)
The pts parameter is an array of points to be drawn. Each point occupies 2 pieces of data.
The offset parameter is the number of skipped data.
The count parameter indicates the number of data actually drawn.


6. public void drawRect (Rect rect, Paint paint)
Public void drawRect (RectF rect, Paint paint)
Public void drawRect (float left, float top, float right, float below, Paint paint)
Used to draw a rectangle


7. public void drawRoundRect (RectF rect, float rx, float ry, Paint paint)
Used to draw rounded rectangle
Rx is the rounded corner radius in the X direction.
Ry is the rounded corner radius in the Y direction.


8. public void drawcirlinoleic (float cx, float cy, float radius, Paint paint)
Used to draw a circle on the canvas
Cx is the x coordinate of the circle.
Cy is the y coordinate of the circle.
Rad indicates the radius of the circle.


9. public void drawOval (RectF rect. Paint paint)
Used to draw an ellipse
Implemented by specifying an exclusive rectangle of an ellipse


10. public void drawPath (Path path, Paint paint)
Used to draw arbitrary polygon on the canvas.


11. public void drawArc (RectF oval, float startAngle, float sweepAngle, 'boolean usecenter, Paint p)
The oval parameter is the elliptical object of the arc.
StartAngle is the starting angle of the arc,
SweepAngle is the arc angle,
UseCenter indicates whether to display the radius line. If the value is true, the line between the arc and the center radius is displayed,


12, public void drawText (String text, float x, float y, Paint paint)
Public void drawText (char [] text, int index, int count, float x, float y, Paint)
Public void drawText (CharSequence text, int start, int end, float x, float y, Paint)
Public void drawText (String text, int start, int end, float x, float y, Paint paint)
The text parameter is a string,
X is the X coordinate
Y is Y coordinate
Index indicates the position of the starting character to be displayed.
Count indicates the number of characters displayed.
Start is the position of the starting character to be displayed.
End is the position of the ending character displayed


13, public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
The bitmap parameter is a Bitmap object that represents image resources,
Left is the position on the left of the image.
Right indicates the right position of the image.


14, public int save ()
Used to lock one or more objects in the canvas. Used to lock objects.
After you use the sava method to lock the canvas and complete the operation, you must use the restore method to unlock the canvas.


15, public Boolean clipRect (Rect rect)
Public Boolean clipRect (float left, float top, float right, float bottom)
Public Boolean clipRect (int left, int top, int right, int boottom)
This method is used to crop the canvas and set the display area of the canvas.


16, public void rotate (float degrees)
Public void rotate (float degrees, float px, float py)
Used to rotate the canvas. by rotating the canvas, you can rotate the objects drawn on the canvas.
The degrees parameter is the rotation angle. The positive value is clockwise and the negative value is clockwise.
Px is the x coordinate of the rotating point.
Py is the y coordinate of the rotation point.

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.