Paint MaskFilter类进行处理、颜色RGB的滤镜处理
来源:互联网 发布:非广播多路访问网络 编辑:程序博客网 时间:2024/06/05 19:09
颜色值时32位的int值,ARGB :A---Alpha值,RGB---颜色值
1、Alpha滤镜处理
MaskFilter类进行处理
BlurMaskFilter--用来绘制模糊阴影
EmbossMaskFilter -- 用来实现浮雕效果
2、颜色RGB的滤镜处理
1、色彩的平移运算---加法运算
在最后一列加上某个值,这样就可以增加特定色彩的饱和度
色彩的反转/反相;增加饱和度
2、色彩的缩放运算--乘法运算
高亮图片
颜色通道过滤(单独红色、绿色、蓝色)
3、色彩的投射运算
黑白照片
色彩反色(两个颜色交换)
复古照片
4、色彩的旋转运算
3、两者混合叠加---Matrix,PortDuffColorFilter
import android.content.Context;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.graphics.BlurMaskFilter;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.ColorMatrix;import android.graphics.ColorMatrixColorFilter;import android.graphics.EmbossMaskFilter;import android.graphics.LightingColorFilter;import android.graphics.MaskFilter;import android.graphics.Paint;import android.graphics.PorterDuff;import android.graphics.PorterDuffColorFilter;import android.graphics.Rect;import android.graphics.RectF;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.view.View;/** * Created by linyaokui on 17/5/17. */public class FilterView extends View{ private Paint paint; private Bitmap bitmap; public FilterView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); paint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmap = BitmapFactory.decodeResource(getResources(),R.mipmap.xyjy2); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); setLayerType(LAYER_TYPE_SOFTWARE,null);//去掉硬件加速 //BlurMaskFilter用法 阴影效果 /** * Create a blur maskfilter. * * @param radius 阴影的半径 * @param style NORMOL -- 整个图像都被模糊掉 * SOLID -- 图像边界外产生一层与Paint颜色一致阴影效果,不影响图像的本身 * OUTER -- 图像边界外产生一层阴影,并且将图像变成透明效果 * INNER -- 在图像内部边沿产生模糊效果 * @return */ MaskFilter maskFilter = new BlurMaskFilter(50, BlurMaskFilter.Blur.NORMAL); paint.setMaskFilter(maskFilter); canvas.drawBitmap(bitmap,100,100,paint); //EmbossMaskFilter 浮雕效果 /** * Create an emboss maskfilter * * @param direction 指定光源的位置,长度为xxx的数组标量[x,y,z] * @param ambient 环境光的因子 (0~1),越接近0,环境光越暗 * @param specular 镜面反射系数 越接近0,镜面反射越强 * @param blurRadius 模糊半径 值越大,模糊效果越明显 */ Rect rect = new Rect(100,100,600,600); paint.setColor(Color.RED); MaskFilter embossMaskFilter = new EmbossMaskFilter(new float[]{1,1,1},0.1f,0.1f,50); paint.setMaskFilter(embossMaskFilter); canvas.drawRect(rect,paint); //颜色RGB的滤镜处理 ColorMatrixColorFilter用法 // 平移运算---加法 ColorMatrix colorMatrix = new ColorMatrix(new float[]{ 1,0,0,0,0, 0,1,0,0,100, 0,0,1,0,0, 0,0,0,1,0, }); // 反相效果 -- 底片效果 ColorMatrix colorMatrix = new ColorMatrix(new float[]{ -1,0,0,0,255, 0,-1,0,0,255, 0,0,-1,0,255, 0,0,0,1,0 }); // 反相效果 -- 底片效果 ColorMatrix colorMatrix = new ColorMatrix(new float[]{ 1.2f,0,0,0,0, 0,1.2f,0,0,0, 0,0,1.2f,0,0, 0,0,0,1.2f,0 }); // 黑白照片 // 去色原理:只要把R G B 三通道的色彩信息设置成一样,那么图像就会变成灰色, // 同时为了保证图像亮度不变,同一个通道里的R+G+B =1 // ColorMatrix colorMatrix = new ColorMatrix(new float[]{ 0.213f, 0.715f,0.072f,0,0, 0.213f, 0.715f,0.072f,0,0, 0.213f, 0.715f,0.072f,0,0, 0,0,0,1,0, }); // 发色效果---(比如红色和绿色交换) ColorMatrix colorMatrix = new ColorMatrix(new float[]{ 0,1,0,0,0, 1, 0,0,0,0, 0,0,1,0,0, 0,0,0,1,0, }); // 复古效果 ColorMatrix colorMatrix = new ColorMatrix(new float[]{ 1/2f,1/2f,1/2f,0,0, 1/3f, 1/3f,1/3f,0,0, 1/4f,1/4f,1/4f,0,0, 0,0,0,1,0, }); // 颜色通道过滤 ColorMatrix colorMatrix = new ColorMatrix(new float[]{ 1, 0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,1,0, }); //另一种写法 ColorMatrix colorMatrix = new ColorMatrix(); ColorMatrix colorMatrix1 = new ColorMatrix(); colorMatrix.setScale(1.2f,1.2f,1.2f,1); colorMatrix.setSaturation(0.5f); //设置饱和度 sat A value of 0 maps the color to gray-scale. 1 is identity //aixs-- 0 红色轴,1,绿色,2,蓝色 // degrees -- 旋转的角度 colorMatrix1.setRotate(0,60); colorMatrix.setConcat(colorMatrix,colorMatrix1);//两个ColorMatrix合并 paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix)); canvas.drawBitmap(bitmap,100,100,paint); // LightingColorFilter只是修改RGB值 LightingColorFilter lightingColorFilter = new LightingColorFilter(0x00ff00,0xff0000); paint.setColorFilter(lightingColorFilter); canvas.drawBitmap(bitmap,100,100,paint); //PorterDuffColorFilter PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(Color.argb(255,140,90,200), PorterDuff.Mode.MULTIPLY); paint.setColorFilter(porterDuffColorFilter); canvas.drawBitmap(bitmap,100,100,paint); }}
阅读全文
0 0
- Paint MaskFilter类进行处理、颜色RGB的滤镜处理
- Android:Paint的setMaskFilter(MaskFilter maskfilter)
- 详解Paint的setMaskFilter(MaskFilter maskfilter)
- 使用jhlabs提供的类对图片进行滤镜处理
- 使用 Java 进行图像处理 - 取得图像上指定位置像素的 rgb 颜色分量
- 使用 Java 进行图像处理 - 取得图像上指定位置像素的 rgb 颜色分量
- android自定义view Paint的setMaskFilter(MaskFilter maskfilter)
- 图像处理详解之MaskFilter
- 图像处理之-----RGB颜色立方体源代码。
- 【图像处理】颜色转换 nv21转rgb rgb转lab
- Paint---MaskFilter(面具)
- Android 背景颜色处理[使用 Drawable.setColorFilter(),或者paint.setColorFilter()]
- 数字图像处理 颜色空间RGB、HSI、CMYK、YUV的相互转换
- 图片颜色处理RGB-拍照-读取相册-保存修改的图片
- 图像处理--RGB与HSI颜色模型的转换方法介绍
- 数字图像处理 颜色空间RGB、HSI、CMYK、YUV的相互转换
- Paint,MaskFilter,FontMetrics及PathEffect
- Android Paint之MaskFilter详解
- memcached win64位服务端安装和java客户端实例
- Android学习三、SurfaceView的学习
- java笔记-多线程join用法
- 使用pytorch预训练模型分类与特征提取
- js获取文件的后缀名方法
- Paint MaskFilter类进行处理、颜色RGB的滤镜处理
- CSDN日报20170601 ——《程序猿职业生涯的迷惘与野望》
- 后代选择器与子选择器
- Python例题8-3~8-4 T恤
- C#学习笔记(八)—–LinqToSql和Entity Framework(上)
- Java程序运行机制
- 记一次oracle创建一个新数据库,并导入正式环境数据库备份的dmp包过程
- sql设计模式
- k-近邻算法