Android滤镜绘制

一、graphics提供的滤镜
二、颜色RAG的滤镜处理

内置滤镜

注意: 使用滤镜之前先关闭硬件加速 
view.setLayerType(LAYER_TYPE_SOFTWARE,mPaint);
  1. MaskFilter

    1. 继承MaskFilter–BlurMaskFilter ,用来设置模糊滤镜
      mPaint.setMaskFilter(BlurMaskFilter(float radius, Blur style));
      radius:模糊半径
      style:有NORMAL、INNER、OUTER、SOLID,默认NORMAL,INNER向绘制区域里面扩散模糊,OUTER向绘制区域外面扩散模糊,SOLID 里外都有。

    2. 继承MaskFilter–EmbossMaskFilter,

/**
     * Create an emboss maskfilter
     *
     * @param direction  array of 3 scalars [x, y, z] specifying the direction of the light source
     * @param ambient    0...1 amount of ambient light
     * @param specular   coefficient for specular highlights (e.g. 8)
     * @param blurRadius amount to blur before applying lighting (e.g. 3)
     * @return           the emboss maskfilter
     */
    public EmbossMaskFilter(float[] direction, float ambient, float specular, float blurRadius) {
        if (direction.length < 3) {
            throw new ArrayIndexOutOfBoundsException();
        }
        native_instance = nativeConstructor(direction, ambient, specular, blurRadius);
    }

这个用起来效果很丑,多于绘制有阴影和有立体感的形状。
3. 继承MaskFilter–TableMaskFilter

颜色滤镜

有个概念叫颜色矩阵 描述ARGB的是四阶矩阵,加上“相加的概念” 有五阶矩阵。美颜相机实现的特效(高光、复古、黑白),各种特效原理都是通过矩阵运算来实现的。

LightingColorFilter
过滤其中的某种颜色,为其中某种颜色值加深

ColorFilter lightingColorFilter = new LightingColorFilter(0x00ffff, 0x000000);  
paint.setColorFilter(lightingColorFilter);  

构造函数:LightingColorFilter(int mul, int add)
参数 :
mul : 乘的数值
add : 增加的数值

PorterDuffColorFilter
跟PorterDuff相关,使用比较简单, 记住17种不同的渲染就好.
ColorMatrixColorFilter
核心:使用一个4*5阶的矩阵(ColorMatrix)来进行颜色转化处理.这里有一个矩阵运算.不太熟悉,可以百度下矩阵相乘相加运算即可.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值