/** * Paint class introduction ** paint is the paint brush, which plays an extremely important role in the drawing process. The paint brush mainly saves the color, * style and other drawing information, and specifies how to draw text and graphics, there are many ways to set a paint brush object. * There are two types in general: one is related to drawing, and the other is related to text painting. ** 1. drawing * setargb (int A, int R, int g, int B); * set the color of the painting. A indicates transparency, R, G, and B indicates the color value. ** Setalpha (int A); * sets the transparency of the drawing. ** Setcolor (INT color); * sets the color of the painting, which is expressed by the color value. The color value includes the transparency and RGB color. ** Setantialias (Boolean aa); * setting whether to use the anti-aliasing function consumes a large amount of resources and slows down the drawing speed. ** Setdither (Boolean dither); * set whether to use image Jitter to make the color of the image smoother and Fuller, and the image clearer. ** setfilterbitmap (Boolean filter ); * If this parameter is set to true, the bitmap image is filtered out during the animation to accelerate the display speed, this setting item depends on dither and xfermode settings ** setmaskfilter (maskfilter); * sets maskfilter. Different maskfilters can be used to implement filter effects, such as filtering, stereo ** setcolorfilter (colorfilter); * sets the color filter to achieve the effect of color conversion when the color is drawn ** setpatheffect (patheffect effect ); * set the effect of the painting path, for example, ** setshader shader (shader); * set the image effect, and use shader to draw various gradient effects ** setshadowlayer (float radius, float dx, float dy, int color); * set the shadow layer under the graph to produce the shadow effect. radius indicates the shadow angle, DX and Dy are the distance between the shadow on the X and Y axes, and color is the shadow color ** setstyle (paint. style); * set the paint brush style to fill, fill_or_stroke, or stroke ** setstrokecap (paint. cap CAP); * When the paint brush style is stroke or fill_or_stroke, set the image style of the brush, such as the circular style * cap. round, or square style cap. square ** setsrokejoin (paint. join join); * set the combination of various images during painting, such as smooth effects ** setstrokewidth (float width); * When the paint brush style is stroke or fill_or_stroke, set the coarse granularity of the brush ** setxfermode (xfermode); * set the processing method when the image overlaps, such as merging, intersection or union, which is often used to make the eraser erasure effect ** 2. text drawing * setfakeboldtext (Boolean fakeboldtext); * simulate and implement bold text, and the effect will be very poor when set to a small font ** setsubpixeltext (Boolean subpixeltext); * set this item to true, will help text display on the LCD screen ** settextalign (paint. align align); * set the alignment direction of the drawn text ** settextscalex (float scalex); * set the zooming ratio of the X axis of the drawn text, you can achieve the effect of text stretching ** settextsize (float textsize); * set the font size of the drawn text ** settextskewx (float skewx); * Set italic text, skewx is a tilting radian ** settypeface (typeface); * sets the typeface object, that is, the font style, including bold, italic, and linebody, ** setunderlinetext (Boolean underlinetext), non-linebody, etc.; * set the text effect with underlines ** setstrikethrutext (Boolean strikethrutext); * set the effect with strikethrough **/
Private Class Myview2 Extends View { Public Myview2 (context ){ Super (Context) ;}@ override Protected Void Ondraw (canvas ){ Super . Ondraw (canvas); canvas. drawcolor (color. White); paint = New Paint (); paint. setantialias ( True ); Paint. setcolor (color. Red); paint. setstyle (paint. style. Stroke ); // Set to hollow Paint. setstrokewidth ( 3 ); Canvas. drawcircle ( 40, 40, 30 , Paint); canvas. drawrect ( 10, 90, 70,150, Paint); canvas. drawrect ( 10,170, 70,200 , Paint); canvas. drawoval ( New Rectf (10,220, 70,250 ), Paint); Path = New PATH (); // Triangle Path. moveTo ( 10,330 ); Path. lineto ( 70,330 ); Path. lineto ( 40,270); Path. Close (); canvas. drawpath (path, paint); Path path1 = New PATH (); // Trapezoid Path1.moveto ( 10,410 ); // Painting basis Path1.lineto ( 70,410 ); Path1.lineto ( 55,350 ); Path1.lineto ( 25,350 ); Path1.close (); // Concatenates the start vertex and the last vertex to form a closed graph. /* * The most important thing is movtto and close. If it is style. Fill, there is no difference if close is not set. However, if it is in stroke mode, * If close is not set, the image is not closed. ** Of course, you can add another line without setting close. The effect is the same. */ Canvas. drawpath (path1, paint ); ////////////////////////////////////// /Second Column Paint. setcolor (color. Blue); paint. setstyle (paint. style. Fill ); // Set solid Canvas. drawcircle ( 120, 40, 30 , Paint); canvas. drawrect ( 90, 90,150,150 , Paint); canvas. drawrect ( 90,170,150,200 , Paint); rectf re2 = New Rectf (90,220,150,250) ); Canvas. drawoval (re2, paint); Path path2 = New PATH (); path2.moveto ( 90,330 ); Path2.lineto ( 150,330); Path2.lineto ( 120,270 ); Path2.close (); canvas. drawpath (path2, paint); Path path3 = New PATH (); path3.moveto ( 90,410 ); Path3.lineto ( 150,410 ); Path3.lineto ( 135,350 ); Path3.lineto ( 105,350 ); Path3.close (); canvas. drawpath (path3, paint ); //////////////////////////////////////// //////////// Column 3 /* * Lineargradient shader = new lineargradient (0, 0, endx, Endy, New * int [] {startcolor, midlecolor, endcolor}, new float [] {0, 0.5f, * 1.0f}, tilemode. mirror); * parameter 1 is the coordinate X position at the beginning of the gradient, parameter 2 is the Y axis, parameter 3 and four resolution correspond to the gradient end * Where parameter new int [] {startcolor, midlecolor, endcolor} is a set of colors involved in the gradient effect. * The New float [] {0, 0.5f, 1.0f} parameter defines the relative position of each color gradient. This parameter can be null, if it is null, all colors are evenly distributed in order. */ Shader mshader = New Lineargradient (0, 0,100,100 , New Int [] {Color. Red, color. Green, color. Blue, color. Yellow }, Null , Shader. tilemode. Repeat ); // Shader. tilemode // Repeat: repeats in the gradient direction. // Clamp: Repeat the color of the boundary if it is drawn out of the pre-defined range. // Mirror: Like repeat, it is a repeating loop, but this will be symmetric. Paint. setshader (mshader ); // Use the color defined in the shader Canvas. drawcircle ( 200, 40, 30 , Paint); canvas. drawrect ( 170, 90,230,150 , Paint); canvas. drawrect ( 170,170,230,200 , Paint); rectf RE3 = New Rectf (170,220,230,250) ); Canvas. drawoval (RE3, paint); Path path4 = New PATH (); path4.moveto ( 170,330); Path4.lineto ( 230,330 ); Path4.lineto ( 200,270 ); Path4.close (); canvas. drawpath (path4, paint); Path path5 = New PATH (); path5.moveto ( 170,410 ); Path5.lineto ( 230,410 ); Path5.lineto ( 215,350 ); Path5.lineto ( 185,350 ); Path5.close (); canvas. drawpath (path5, paint ); ////////////////////////////////// 4th columns Paint. settextsize ( 24 ); Canvas. drawtext ( "Circle", 240, 50 , Paint); canvas. drawtext ( "Square", 240,120 , Paint); canvas. drawtext ( "Rectangle", 240,190 , Paint); canvas. drawtext ( "Oval", 240,250 , Paint); canvas. drawtext ( "Triangle", 240,320 , Paint); canvas. drawtext ( "Trapezoid", 240,390, Paint );}}