Android学习之Paint图形图像处理(二)

本文深入探讨Android中的Path及其PathEffect子类,介绍如何使用Path.drawPath和Path.op方法进行图形绘制和组合操作。通过代码示例展示了不同PathEffect效果,如DashPathEffect、ComposePathEffect等,并详细解释了Path.op方法的不同参数对图形的影响。
摘要由CSDN通过智能技术生成

Path

是什么

Path即路径,通过canvas的drawPath(path,paint)方法,按照指定的路径去绘制。

怎么样

Android中还为路径绘制提供了PathEffect的来指定绘制的效果,PathEffect包含了几个子类DashPathEffect,ComposePathEffect,SumPathEffect,CornerPathEffect,DiscretePathEffect,PathDashPathEffect。Path还有Path.op方法用于对两个Path对象做相应的运算组合(combine),具体的说是根据不同的op参数及path2参数来影响path1对象,有点类似于数学上的集合运算…….

怎么用

PathEffect

pathEffect几个子类的效果很难描述,用demo表示,看运行效果
这里写图片描述

其中有虚线的是有动画的,看着眼花缭乱,最明显的就是虚线和实线的区别,那两条实线没看出有什么区别,其余的虚线,也大同小异。

代码演示

新建项目,创建MyPathView类继承View重写三个构造方法
在构造方法中初始化画笔

package com.cd.pathdemo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposePathEffect;
import android.graphics.CornerPathEffect;
import android.graphics.DashPathEffect;
import android.graphics.DiscretePathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathDashPathEffect;
import android.graphics.PathEffect;
import android.graphics.SumPathEffect;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by Sky
 * on 2016/10/30.
 * Describe:
 */

public class MyPathView extends View {
   

    int[] colors;
    Paint mPaint;
    float phase;
    Path path;
    PathEffect[] patheffect = new PathEffect[7];

    public MyPathView(Context context) {
        super(context);

        init();

    }


    public MyPathView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyPathView(Context context, Attri
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值