Package com.example.android.apis.graphics;
23.TextAlign:
Set path path, Bezier curve
// set path Path Private Static void Makepath (Path p) { P.moveto (0); P.cubicto (100,-50, 200, 50, 300, 0); // Bézier curve }
MPOs is the position coordinates of each character in the string.
Private float[] buildtextpositions (String text,floaty, Paint paint) { float[] widths =New float[Text.length ()]; //initially get the widths for each char intn =paint.gettextwidths (text, widths); //Now popuplate the array, interleaving spaces for the Y values X is the width of the character float[] pos =New float[N * 2]; floatAccumulatedx = 0; for(inti = 0; I < n; i++) {pos[i* 2 + 0] =Accumulatedx; Pos[i* 2 + 1] =y; Accumulatedx+=Widths[i]; } returnPOS; }
In the OnDraw () method:
Draw
P.setcolor (0x80ff0000); + DY * 3, p); // (x, y) is a baseline P.setcolor (color.black); Canvas.translate (0, DY); P.settextalign (Paint.Align.LEFT); Canvas.drawtext (text_l, x, Y, p); // at (x, y) point Paint.Align.LEFT,
Draw
Draw
P.setcolor (0xbb00ff00); for (int i = 0; i < POS.LENGTH/2; i++) { * 2 + 0], Pos[i * 2 + 1]-DY, Pos[i * 2 + 0], * 2 + 1] + DY * 2, p); } P.setcolor (color.black); P.settextalign (Paint.Align.LEFT); Canvas.drawpostext (Postext, POS, p);
Draw
Canvas.drawpath (MPath, mpathpaint); P.settextalign (Paint.Align.LEFT); 0, 0, p); Canvas.translate (0, DY * 1.5f); Canvas.drawpath (MPath, mpathpaint); P.settextalign (Paint.Align.CENTER); 0, 0, p); Canvas.translate (0, DY * 1.5f); Canvas.drawpath (MPath, mpathpaint); P.settextalign (Paint.Align.RIGHT); 0, 0, p);
24.Typefaces:
Get the font under Assets/fonts
Mface = Typeface.createfromasset (GetContext (). Getassets (), "Fonts/samplefont.ttf");
OnDraw () method
@Override protectedvoid onDraw (canvas canvas) { Canvas.drawcolor ( Color.White); Mpaint.settypeface (null); Canvas.drawtext ("Default", ten,mpaint); Mpaint.settypeface (mface); Canvas.drawtext ("Custom", ten, Max, mpaint); }
25.UnicodeChart: (not seen)
26.Vertices: (not see) touch, picture shape
27.Xfermodes:
Round drawing:
Static Bitmap makedst (intint h) { = bitmap.createbitmap (w, H, Bitmap.Config.ARGB_8888); New Canvas (BM); New Paint (paint.anti_alias_flag); P.setcolor (0xffffcc44); C.drawoval (new rectf (0, 0, W * 3/4, H * 3/4), p); return BM; }
The drawing of a square:
Static Bitmap makesrc (intint h) { = bitmap.createbitmap (w, H, Bitmap.Config.ARGB_8888); New Canvas (BM); New Paint (paint.anti_alias_flag); P.setcolor (0xff66aaff); /3, H/3, W * 19/20, H * 19/20, p); return BM; }
Background mosaic:
Bitmap BM = Bitmap.createbitmap (newint[] {0xFFFFFFFF, 0xFFCCCCCC, 0xFFCCCCCC, 0xFFFFFFFF}, 2, 2, Bitmap.Config.RGB_565); New Bitmapshader (BM, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); New Matrix (); M.setscale (6, 6); // zoom in 6 times times Mbg.setlocalmatrix (m);
Xfermode array:
Private Static Finalxfermode[] Smodes = { NewPorterduffxfermode (PorterDuff.Mode.CLEAR),NewPorterduffxfermode (PorterDuff.Mode.SRC),NewPorterduffxfermode (PorterDuff.Mode.DST),NewPorterduffxfermode (PorterDuff.Mode.SRC_OVER),NewPorterduffxfermode (PorterDuff.Mode.DST_OVER),NewPorterduffxfermode (PorterDuff.Mode.SRC_IN),NewPorterduffxfermode (PorterDuff.Mode.DST_IN),NewPorterduffxfermode (PorterDuff.Mode.SRC_OUT),NewPorterduffxfermode (PorterDuff.Mode.DST_OUT),NewPorterduffxfermode (PorterDuff.Mode.SRC_ATOP),NewPorterduffxfermode (PorterDuff.Mode.DST_ATOP),NewPorterduffxfermode (PorterDuff.Mode.XOR),NewPorterduffxfermode (PorterDuff.Mode.DARKEN),NewPorterduffxfermode (PorterDuff.Mode.LIGHTEN),NewPorterduffxfermode (PorterDuff.Mode.MULTIPLY),NewPorterduffxfermode (PorterDuff.Mode.SCREEN)};
OnDraw () Method:
@Overrideprotected voidOnDraw (canvas canvas) {canvas.drawcolor (color.white); Paint Labelp=NewPaint (Paint.anti_alias_flag); Labelp.settextalign (Paint.Align.CENTER); Paint Paint=NewPaint (); Paint.setfilterbitmap (false); Canvas.translate (15, 35); intx = 0; inty = 0; for(inti = 0; i < smodes.length; i++) { //Draw the BorderPaint.setstyle (Paint.Style.STROKE); Paint.setshader (NULL);//Pass Null to clear any previous shaderCanvas.drawrect (x-0.5f, y-0.5f, x + W + 0.5f, y + H + 0.5f, paint); //Draw the Checker-board patternPaint.setstyle (Paint.Style.FILL); Paint.setshader (MBG); Canvas.drawrect (x, y, x+ W, Y +H, paint); //Draw the src/dst example into our offscreen bitmap intsc = Canvas.savelayer (x, y, x + W, y + H,NULL, Canvas.matrix_save_flag|Canvas.clip_save_flag|Canvas.has_alpha_layer_save_flag|Canvas.full_color_layer_save_flag|Canvas.clip_to_layer_save_flag); //Canvas.save ();canvas.translate (x, y); Canvas.drawbitmap (MDSTB,0, 0, paint); Paint.setxfermode (Smodes[i]); Canvas.drawbitmap (MSRCB,0, 0, paint);
Android.apis.graphics Drawing (citation)