Summary of methods of paint class and canvas class in Android

Common methods of the paint class

1. SetColor method, used to set the color of the brush,

Public void SetColor (int color) / / the parameter color is the color value. You can also use the color defined by the color class

Color.black: Black

Color. Blue: Blue

Color. Cyan: Turquoise

Color.dkgray: grayish black

Color. Yellow: yellow

Color.gray: gray

Color. Green: Green

Color.ltgray: light green

Color. Magenta: red purple

Color. Transparent: transparent color

2. Setalpha method, used to set the transparency of the brush

Public void setalpha (int a) / / parameter a is transparency. Its value range is 0 ~ 255. The smaller the value, the more transparent it is

3. Setstyle method is used to set the style of the brush. You can specify whether it is a circle center or a solid. This method has obvious effects on rectangles and circles

Public void setstyle (paint. Style style) / / parameter style is the style of the brush

Style.fill: solid

Style.FILL_ AND_ Stroke: displays both solid and void

Style.stroke: Hollow

4. Setstrokewidth method is used to set the hollow line width of the brush. This method has obvious effects on rectangular, circular, and other graphics

Public void setstrokewidth (float width) / / parameter width is the line width, floating-point data

5. Settextsize method is used to set the font size of the brush, which is mainly used to draw strings

public void setTextSize(float textSize)//

6. The settypeface method is used to set the font style of the brush. You can use the fields provided by the system or the custom font

Public void typeface (typeface typeface) / / typeface is 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 scale factor of brush font. The default is 1. When it is greater than 1, it means horizontal stretching, and when it is less than 1, it means horizontal compression

public void setTextScaleX(float scaleX)

8. Setargb method, which is used to set the color and transparency of the brush

public void setARGB(int a,int r,int g,int b);

Parameter a is transparency, ranging from 0 to 255

Parameter r is the color value of red, ranging from 0 to 255

The parameter g is the color value of green, ranging from 0 to 255

Parameter B is the color value of blue, ranging from 0 to 255

9. Setunderlinetext method, which is used to set the underline of the brush

public void setUnderlineText(Boolean underlintext)

When the value is true, the underline is displayed

10. Settextskewx method, which is used to set the tilt factor of the brush

public void setTextSkewX(float skewX)

Parameter skewx is the tilt factor. A positive number indicates tilt to the left and a negative number indicates tilt to the right

Method of canvas class

1.public void drawColor(int color)

Sets the background color of the canvas

2.public void drawLine(float starX,float startY,float stopX,float stopY,Paint paint);

Lets you draw a line on the canvas

The parameters are the X coordinate and Y coordinate of the starting point of the line, the X coordinate and Y coordinate of the ending point, and the brush used

3.public void drawLines(float[] pts,Paint paint)

Lets you draw multiple lines on the canvas

Parameter PTS is the endpoint array of the drawn line, and each line occupies 4 data

4.public void drawPoint(float x,float y,Paint paint)

Lets you draw points on the canvas

The parameters are the X and Y coordinates of the point and the brush used

5.public void drawPoints(float[] pts,Paint paint)

public void drawPoints(float[] pts,int offset,int count,Paint paint)

Parameter PTS is an array of drawing points, and each point occupies 2 data

Parameter offset is the number of skipped data

The parameter count is the number of data actually involved in drawing

6.public void drawRect(Rect rect,Paint paint)

public void drawRect(RectF rect,Paint paint)

public void drawRect(float left,float 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 rectangles

Rx is the fillet radius in the X direction

Ry is the fillet radius in the Y direction

8.public void drawCircla(float cx,float cy,float radius,Paint paint)

Lets you draw a circle on the canvas

CX is the X coordinate of the circle

CY is the Y coordinate of the circle

Rad is the radius of the circle

9.public void drawOval(RectF rect.Paint paint)

Used to draw ellipses

This is achieved by specifying the circumscribed rectangle of the ellipse

10.public void drawPath(Path path,Paint paint)

It is used to draw arbitrary polygons on the canvas

11.public void drawArc(RectF oval,float startAngle,float sweepAngle,`Boolean usecenter,Paint p)

The parameter oval is the ellipse object where the arc is located

Startangle is the starting angle of the arc,

Sweepangle is the angle of the arc,

Usecenter indicates whether to display the radius line. When the value is true, the radius line between the arc and the center of the circle is displayed,

12,public void drawText(String text,float x,Paint paint)

public void drawText(char[] text,int index,Paint paint) public void drawText(CharSequence text,int start,int end,Paint paint) public void drawText(String text,Paint paint)

The parameter text is the content of the string,

X is the X coordinate

Y is the Y coordinate

Index is the starting character position of the display

Count is the number of characters displayed

Start is the position of the starting character displayed

End is the position of the terminated character displayed

13,public void drawBitmap(Bitmap bitmap,float left,float top,Paint paint)

The parameter bitmap is a bitmap object, representing image resources,

Left is the left position of the image display

Right is the right position of the image display

14,public int save()

It is used to lock one or several objects in the canvas, and is used to lock object operations

After using the Sava method to lock the canvas and complete the operation, you need to use the restore method to unlock it

15,public Boolean clipRect(Rect rect)

public Boolean clipRect(float left,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 painted on the canvas

The parameter degrees is the angle of rotation. A positive number is clockwise and a negative number is counterclockwise

PX is the X coordinate of the rotation point

Py is the Y coordinate of the rotation point

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>