Board logo

标题: Android Canvas之Path操作(5) [打印本页]

作者: look_w    时间: 2019-2-19 16:33     标题: Android Canvas之Path操作(5)

绘制常规图形示例:

    //初始化Paint
    Paint paint = new Paint();
    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(10f);
    Path path = new Path();
    //以(400,200)为圆心,半径为100绘制圆
    path.addCircle(400, 200, 100, Path.Direction.CW);
     
    //绘制椭圆
    RectF rectF = new RectF(100, 350, 500, 600);
    //第一种方法绘制椭圆
    path.addOval(rectF, Path.Direction.CW);
    //第二种方法绘制椭圆
    path.addOval(600, 350, 1000, 600, Path.Direction.CW);
     
    //绘制矩形
    RectF rect = new RectF(100, 650, 500, 900);
    //第一种方法绘制矩形
    path.addRect(rect, Path.Direction.CW);
    //第一种方法绘制矩形
    path.addRect(600, 650, 1000, 900, Path.Direction.CCW);
     
    //绘制圆角矩形
    RectF roundRect = new RectF(100, 950, 300, 1100);
    //第一种方法绘制圆角矩形
    path.addRoundRect(roundRect, 20, 20, Path.Direction.CW);
    //第二种方法绘制圆角矩形
    path.addRoundRect(350, 950, 550, 1100, 10, 50, Path.Direction.CCW);
    //第三种方法绘制圆角矩形
    //float[] radii中有8个值,依次为左上角,右上角,右下角,左下角的rx,ry
    RectF roundRectT = new RectF(600, 950, 800, 1100);
    path.addRoundRect(roundRectT, new float[]{50, 50, 50, 50, 50, 50, 0, 0}, Path.Direction.CCW);
    //第四种方法绘制圆角矩形
    path.addRoundRect(850, 950, 1050, 1100,new float[]{0, 0, 0, 0,50, 50, 50, 50}, Path.Direction.CCW);
    canvas.drawPath(path, paint);





欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0