1.Paint brushes
A panit (brush) is a drawing amount helper class that contains attribute information such as text and bitmap amount styles, colors, and so on. The common methods for Paint are as follows:
Setantialias (Boolean AA)
Function: Sets whether the brush is non-aliased
Parameters: True for no aliasing, false for aliasing, false for default.
Setalpha (int a)
Function: Sets the transparency of the brush
Parameters: Transparent values
SetTextAlign (Paint.align Align)
Function: Sets the anchor point of the drawing text
Parameters: Constants in the Paint.align class
Measuretext (String text)
Function: Gets the width of the text content
Parameters: Text content
SetStyle (Style style)
Action: Set Brush style
Parameters: Style Instances
SetColor (int color)
Action: Set Brush color
Parameters: Color values
Setstrokewidth (float width)
Effect: Set Brush amount Thickness
Parameters: Brush Thickness values
Settextsize (float textSize)
Function: Sets the size of the text font when the brush draws text
Parameters: Dimension values
Setargb (int a,int r,int g,int b)
Function: Sets the ARGB component of the brush
First parameter: Brush transparency component
Second parameter: Red component of brush
Third parameter: Brush green component
Fourth parameter: Blue component of brush
2.Paint Brush Instances
As follows:
Step: New Project "Panitproject", the game frame for the Mysurfaceview game framework, the specific steps refer to "11. Game Development Basics (Surfaceview game frame, View and Surfaceview differences)".
The main drawing Method Mydraw () is modified as follows:
Public voidMydraw () {Try{Canvas=Sfh.lockcanvas (); if(canvas!=NULL) {canvas.drawcolor (color.white); //--Set brush non-aliasingPaint Paint1 =NewPaint (); Canvas.drawcircle (40,30,20, Paint1); Paint1.setantialias (true); Canvas.drawcircle (100,30,20, Paint1); //--Set the transparency of the brushCanvas.drawtext ("No transparency", 100, 70,NewPaint ()); Paint Paint2=NewPaint (); Paint2.setalpha (0x77); Canvas.drawtext ("Semi-transparent", 20, 70,NewPaint ()); //--set anchor points for drawing textCanvas.drawtext ("Anchor Point", 20, 90,NewPaint ()); Paint Paint3=NewPaint (); //setting is drawn as the center point of the textpaint3.settextalign (Paint.Align.CENTER); Canvas.drawtext ("Anchor Point", 20,105, Paint3); //--Get the length of the textPaint paint4 =NewPaint (); floatLen = Paint4.measuretext ("Text width:"); Canvas.drawtext ("Text length:" +len,20,130,NewPaint ()); //--Set brush styleCanvas.drawrect (NewRect (20,140,40,160),NewPaint ()); Paint paint5=NewPaint (); //set Brush is not populatedPaint5.setstyle (Paint.Style.STROKE); Canvas.drawrect (NewRect (60,140,80,160), PAINT5); //--Set brush colorPaint paint6 =NewPaint (); Paint6.setcolor (Color.Blue); Canvas.drawtext ("Blue", 30,180, PAINT6); //--Set the thickness of the brushCanvas.drawline (20,200,70,200,NewPaint ()); Paint paint7=NewPaint (); Paint7.setstrokewidth (7); Canvas.drawline (20,220,70,220, paint7); //--Set the font weight of the brush drawing textPaint paint8 =NewPaint (); Paint8.settextsize (20); Canvas.drawtext ("Text Size", 20,260, paint8); //--Set the ARGB component of the brushPaint paint9 =NewPaint (); Paint9.setargb (0x77,0xff,0x00,0x00); Canvas.drawtext ("Red translucent", 20,290, PAINT9); } } Catch(Exception ex) {}finally { if(canvas!=NULL) {sfh.unlockcanvasandpost (canvas); } } }
The Paint brush class provides an anti-aliasing function, in fact the canvas canvas also provides the amount of plot antialiasing functions, as follows:
Canvas.setdrawfilter (Drawfilter filter);
Function: Set drawing antialiasing for the canvas
Parameters: Drawing Filter Instance
Instantiate an object of the Drawfilter class, as shown in the following code:
New Paintflagsdrawfilter (0,paint.anti_alias_flag| Paint.filter_bitmap_flag);
"The zero start of Android game programming" 13. Game Development Basics (Paint brush)