Android图像处理之霓虹滤镜效果
作者:HQUZkP 时间:2023-08-11 14:37:41
霓虹是用来描绘图像的轮廓,勾画出颜色变化的边缘,加强其过度效果,使图像产生轮廓发光的效果。
主要步骤:
1、根据当前像素与其右方和下方像素的梯度运算;
2、然后将结果值作为当前像素值,即将原图当前下像素的RGB分量与其右方和下方像素做梯度 运算(差的平方和平方根);
3、然后将梯度值作为处理后的像素的RGB三个分量;
用代码实现如下:
//霓虹
public static Bitmap Neon(Bitmap bitmap){
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Bitmap resultBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
int color = 0;
int r,g,b,r1,g1,b1,r2,g2,b2;
int[] oldPx = new int[w * h];
int[] newPx = new int[w * h];
bitmap.getPixels(oldPx, 0, w, 0, 0, w, h);
for(int y = 0; y < h - 1; y++){
for(int x = 0; x < w - 1; x++){
color = oldPx[x+y*w];
r = (color >> 16) & 0xFF;
g = (color >> 8) & 0xFF;
b = (color >> 0) & 0xFF;
int newcolor = oldPx[x+1+y*w];
r1 = (newcolor >> 16) & 0xFF;
g1 = (newcolor >> 8) & 0xFF;
b1 = (newcolor >> 0) & 0xFF;
int newcolor2 = oldPx[x+(y+1)*w];
r2 = (newcolor2 >> 16) & 0xFF;
g2 = (newcolor2 >> 8) & 0xFF;
b2 = (newcolor2 >> 0) & 0xFF;
int tr = (int) (2*Math.sqrt(((r-r1)*(r-r1)+(r-r2)*(r-r2))));
int tg = (int) (2*Math.sqrt(((g-g1)*(g-g1)+(g-g2)*(g-g2))));
int tb = (int) (2*Math.sqrt(((b-b1)*(b-b1)+(b-b2)*(b-b2))));
newPx[x+y*w] = (255 << 24)|(tr << 16)|(tg << 8)|(tb);
}
}
resultBitmap.setPixels(newPx, 0, w, 0, 0, w, h);
return resultBitmap;
}
对应的效果图如下:
原图如下:
挺具有魔幻色彩的。
标签:Android,图像处理,霓虹滤镜
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C#微信公众号与订阅号接口开发示例代码
2023-07-20 09:11:07
Android实现简易计算功能
2022-01-10 20:42:59
![](https://img.aspxhome.com/file/2023/1/138891_0s.jpg)
wpf将表中数据显示到datagrid示例
2023-06-13 04:14:06
Android Drawable代码编写的新姿势分享
2021-11-21 04:11:12
![](https://img.aspxhome.com/file/2023/8/122208_0s.png)
Room Kotlin API的使用入门教程
2023-11-07 07:06:35
Java 中String StringBuilder 与 StringBuffer详解及用法实例
2021-06-17 12:25:32
java数据结构与算法之双向循环队列的数组实现方法
2022-08-12 23:24:44
Java使用原型模式展现每日生活应用案例详解
2023-03-08 04:27:08
![](https://img.aspxhome.com/file/2023/3/87373_0s.png)
spring mvc实现登录账号单浏览器登录
2022-06-28 22:29:47
2020最新 idea下载、安装与创建项目测试的教程图解
2023-10-22 08:08:14
![](https://img.aspxhome.com/file/2023/2/129952_0s.png)
Android 修改adb端口的方法
2021-07-11 02:42:24
![](https://img.aspxhome.com/file/2023/0/137320_0s.jpg)
详解C#中的System.Timers.Timer定时器的使用和定时自动清理内存应用
2022-11-07 14:09:54
MyBatis绑定错误提示BindingException:Invalid bound statement (not found)的解决方法
2021-10-22 03:58:44
springboot mybatis里localdatetime序列化问题的解决
2023-06-25 06:58:18
Android实现摄像头拍照功能
2022-04-25 13:05:55
Android逆向入门之常见Davlik字节码解析
2023-09-13 02:53:10
![](https://img.aspxhome.com/file/2023/2/138372_0s.png)
Android通过Handler与AsyncTask两种方式动态更新ListView(附源码)
2022-04-14 03:32:22
Android自定义View实现竖向滑动回弹效果
2021-08-03 12:19:00
JFileChooser实现对选定文件夹内图片自动播放和暂停播放实例代码
2021-10-02 15:41:18
C#泛型用法实例分析
2021-10-16 14:01:49