andorid 绘制

        // 指南针上和下
//        Path compass_top = new Path();
//        compass_top.moveTo(0, -mRadius);
//        compass_top.lineTo(-mHeartPaintWidth * 3, 0);
//        compass_top.lineTo(mHeartPaintWidth * 3, 0);
//        compass_top.lineTo(0, -mRadius);
//        canvas.drawPath(compass_top, paint_top);
//        Path compass_bottom = new Path();
//        compass_bottom.moveTo(0, mRadius);
//        compass_bottom.lineTo(-mHeartPaintWidth * 3, 0);
//        compass_bottom.lineTo(mHeartPaintWidth * 3, 0);
//        compass_bottom.lineTo(0, mRadius);
//        canvas.drawPath(compass_bottom, paint_bottom);
        // 画中心圆
//        canvas.drawCircle(0, 0, mHeartPaintWidth * 3, mRingPaintCenter);
mDefPenDash.setPathEffect(new DashPathEffect(new float[]{2, 2}, 0));虚线画笔
// 平移坐标系   canvas.translate(0, height);

绘制封闭椭圆扇形

canvas.setDrawFilter(mDrawFilter);
        float top = height * 16 / 95f;
        RectF baseRect = new RectF(-0.27f * width, top, 1.27f * width, 4.5f * height);
        Path path = new Path();
        float startA = -125;
        float aCha = 70f / 100;
        // todo 开始的点固定 计算结束的点
        path.arcTo(baseRect, startA, aCha * degree);
        float x = width * 1 / 18f;
        float y = height * 11 / 19f;
        baseRect.inset(x, y);
        float allB = -59f - 60.5f;
        float bCha = -59f / 100;
        float degreeB = bCha * degree;
        LogUtils.e(String.format("cmy:%d:%f,%d:%f,top:%f", width, x, height, y, top));
        // todo 结束的点固定 计算开始点 因为首位相连 所有这里要反着写角度问题  -61f,-58.5f
//        path.arcTo(baseRect, -60.5f, -59f);
        path.arcTo(baseRect, allB - degreeB, degreeB);
        path.close();
        canvas.drawPath(path, mRingPaintCenter);

自定义的界面 继承view 重写

@Override
protected void onDraw(Canvas canvas)方法

Path之贝塞尔曲线

可以用二阶贝塞尔曲线来实现线段的转折呢,从而实现线段之间的平滑过渡

//二阶贝赛尔

public void quadTo(float x1, float y1, float x2, float y2)

quadTo方法,有四个参数,其中x1和y1是指控制点的坐标,x2和y2是终点的坐标,那起点的坐标在哪里呢?其实起点的坐标就是上一个曲线的终点坐标,或者Path开始的moveTo方法的坐标,如果没有指定起点坐标,那么就会默认为原点了。

public void rQuadTo(float dx1, float dy1, float dx2, float dy2)

其实rQuadTo和quadTo的使用效果是一样的,都是二阶贝塞尔曲线的函数,只不过它们参数的意义有差别。rQuadTo的参数的值是以上一个曲线的终点作为参照的相对值

其中:dx1和dy1作为当前曲线的控制点相对于上一个终点增加或减少的相对值,可正可负。dx2和dy2则作为当前曲线终点的相对值

//
Path cmyPath = new Path();
cmyPath.moveTo(0, 0);
cmyPath.quadTo(20, -150, 100, -200);
cmyPath.quadTo(150, -150, 200, -50);
canvas.drawPath(cmyPath, mWavePenQuad);
//
Path cmyPath1 = new Path();
cmyPath1.moveTo(0, 0);
cmyPath1.quadTo(20, -150, 60, -175);
cmyPath1.quadTo(100, -200, 125, -175);
cmyPath1.quadTo(150, -150, 175, -100);
cmyPath1.quadTo(200, -50, 210, -150);
cmyPath1.quadTo(220, -250, 235, -225);
canvas.drawPath(cmyPath1, mDefPenDash);
//
Path cmyPath2 = new Path();
cmyPath2.moveTo(0, 0);
cmyPath2.lineTo(20, -150);
cmyPath2.lineTo(100, -200);
cmyPath2.lineTo(150, -150);
cmyPath2.lineTo(200, -50);
cmyPath2.lineTo(220, -250);
cmyPath2.lineTo(250, -200);
canvas.drawPath(cmyPath2, mWavePen);

android中Invalidate和postInvalidate的区别  前者是在ui线程里  后者是在非ui线程里刷新  除了onCreate()是运行在UI线程上的,其实其他大部分方法都是运行在UI线程上的,其实其实只要你没有开启新的线程,你的代码基本上都运行在UI线程上。

Paint.Style.FILL、Paint.Style.STROKE和Paint.Style.FILL_AND_STROKE。

当style为FILL时,绘制是填充面,FILL是Paint默认的style;

当style为STROKE时,绘制的是图形的轮廓线;

当style为FILL_AND_STROKE时,同时绘制填充面和轮廓线,不过这种情况用的不多,因为填充面和轮廓线是用同一种颜色绘制的,区分不出轮廓线的效果。

坐标系开始从左上角 {[0,0] ; [width,height]}往右变大,往下变大,一般可以移动坐标系来计算

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值