canvas教程

Android基础入门教程——8.3.1 三个绘图工具类详解(3)

字号+ 作者:H5之家 来源:H5之家 2015-10-31 09:01 我要评论( )

6)绘制圆角矩形canvas.drawRoundRect(new RectF(10,10,210,110),15,15,mPaint); //画圆角矩形 7)绘制椭圆canvas.drawOval(new RectF(0,0,200,300),mPaint); //画椭圆 8)绘制多边形: Path path = new Path(); pat

6)绘制圆角矩形 canvas.drawRoundRect(new RectF(10,10,210,110),15,15,mPaint); //画圆角矩形

title=

7)绘制椭圆 canvas.drawOval(new RectF(0,0,200,300),mPaint); //画椭圆

title=

8)绘制多边形: Path path = new Path(); path.moveTo(10, 10); //移动到 坐标10,10 path.lineTo(100, 50); path.lineTo(200,40); path.lineTo(300, 20); path.lineTo(200, 10); path.lineTo(100, 70); path.lineTo(50, 40); path.close(); canvas.drawPath(path,mPaint);

title=

9)绘制文字: canvas.drawText(最喜欢看曹神日狗了~,50,50,mPaint); //绘制文字

你也可以沿着某条Path来绘制这些文字:

Path path = new Path(); path.moveTo(50,50); path.lineTo(100, 100); path.lineTo(200, 200); path.lineTo(300, 300); path.close(); canvas.drawTextOnPath(最喜欢看曹神日狗了~, path, 50, 50, mPaint); //绘制文字

title=

10)绘制自定义的图形:

代码来源于网上:

protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.translate(canvas.getWidth()/2, 200); //将位置移动画纸的坐标点:150,150 canvas.drawCircle(0, 0, 100, mPaint); //画圆圈 //使用path绘制路径文字 canvas.save(); canvas.translate(-75, -75); Path path = new Path(); path.addArc(new RectF(0,0,150,150), -180, 180); Paint citePaint = new Paint(mPaint); citePaint.setTextSize(14); citePaint.setStrokeWidth(1); canvas.drawTextOnPath(绘制表盘~, path, 28, 0, citePaint); canvas.restore(); Paint tmpPaint = new Paint(mPaint); //小刻度画笔对象 tmpPaint.setStrokeWidth(1); float y=100; int count = 60; //总刻度数 for(int i=0 ; i

title=

://www.bkjia.com/Androidjc/1062896.htmlTechArticleAndroid基础入门教程——8.3.1 三个绘图工具类详解 上两小节我们学习了Drawable以及Bitmap,都是加载好图片的,而本节我们要学习的绘图相关的...

  • 上一篇:Android Studio下加入百度地图的使用 (一)——环境搭建,androidstudio
  • 下一篇:Android_02_文件访问权限(待更新)
  •  

    1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    相关文章
    • Canvas与ValueAnimator

      Canvas与ValueAnimator

      2017-04-28 18:00

    • Canvas学习:绘制矩形

      Canvas学习:绘制矩形

      2017-04-24 17:02

    • Windows GDI和GDI+编程实例剖析

      Windows GDI和GDI+编程实例剖析

      2017-04-24 13:00

    • JavaScript Canvas绘制圆形时钟效果

      JavaScript Canvas绘制圆形时钟效果

      2017-04-21 09:04

    网友点评
    #