一、graphics提供的滤镜
二、颜色RAG的滤镜处理
内置滤镜
注意: 使用滤镜之前先关闭硬件加速
view.setLayerType(LAYER_TYPE_SOFTWARE,mPaint);
MaskFilter
继承MaskFilter–BlurMaskFilter ,用来设置模糊滤镜
mPaint.setMaskFilter(BlurMaskFilter(float radius, Blur style));
radius:模糊半径
style:有NORMAL、INNER、OUTER、SOLID,默认NORMAL,INNER向绘制区域里面扩散模糊,OUTER向绘制区域外面扩散模糊,SOLID 里外都有。继承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)来进行颜色转化处理.这里有一个矩阵运算.不太熟悉,可以百度下矩阵相乘相加运算即可.