原文:图像滤镜艺术---Glow Filter发光滤镜

Glow Filter发光滤镜

Glow Filter发光滤镜是一种让图像产生发光效果的滤镜,它的实现算法如下:
1,对原图P进行高斯模糊得到图像A;
2,将P和A进行“叠加”图层混合处理,公式如下:
Result(x,y) = ((basePixel(x,y) <= 128) ? (mixPixel(x,y) * basePixel(x,y) /
128):(255 - (255 - mixPixel(x,y)) * (255 - basePixel(x,y))
/ 128));
注意:Result(x,y)属于[0-255];
以上就是发光滤镜的原理。
核心代码如下:
private Bitmap GlowFilterProcess(Bitmap src)
        {
            Bitmap gaussBitmap = gf.Apply(src, 15);   
            Bitmap dst = new Bitmap(src);
            int w = dst.Width;
            int h = dst.Height;
            BitmapData dstData = dst.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            BitmapData gaussData = gaussBitmap.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            byte* pGauss = (byte*)gaussData.Scan0;
            byte* pDst = (byte*)dstData.Scan0;
            int offset = dstData.Stride - w * 4;
            int gray;
            for (int j = 0; j < h; j++)
            {
                for (int i = 0; i < w; i++)
                {
                    gray = ((pDst[0] <= 128) ? (pGauss[0] * pDst[0] / 128) : (255 - (255 - pGauss[0]) * (255 - pDst[0]) / 128));
                    gray = Math.Min(255, Math.Max(0, gray));
                    pDst[0] = (byte)gray;
                    gray = ((pDst[1] <= 128) ? (pGauss[1] * pDst[1] / 128) : (255 - (255 - pGauss[1]) * (255 - pDst[1]) / 128));
                    gray = Math.Min(255, Math.Max(0, gray));
                    pDst[1] = (byte)gray;
                    gray = ((pDst[2] <= 128) ? (pGauss[2] * pDst[2] / 128) : (255 - (255 - pGauss[2]) * (255 - pDst[2]) / 128));
                    gray = Math.Min(255, Math.Max(0, gray));
                    pDst[2] = (byte)gray;
                    pDst[3] = (byte)255;
                    pGauss += 4;
                    pDst += 4;
                }
                pGauss += offset;
                pDst += offset;
            }
            dst.UnlockBits(dstData);
            gaussBitmap.UnlockBits(gaussData);
            return dst;
        }
效果图如下:

原图

Glow Filter效果图

最后放上一个完整的 C# 程序Demo下载地址:http://www.zealpixel.com/thread-65-1-1.html

最新文章

  1. powershell中使用超大内存对象
  2. 相机标定:Matlab标定工具箱使用要点
  3. APP架子迁移指南(二)
  4. ini 文件
  5. (转)FirstResponder 释放问题
  6. Shell脚本[运算表达式,条件控制语句]
  7. bootstrap表格多样式及代码
  8. bnuoj 33648 Neurotic Network(树形模拟题)
  9. protobuf-3.0.0-beta-2 windows编译 x64/x86
  10. Synopsys逻辑工艺库
  11. 我的2017&amp;2018
  12. [洛谷P2627] 修剪草坪
  13. 附9 elasticsearch-curator + Linux定时任务
  14. ASP.NET MVC使用Oauth2.0实现身份验证
  15. 为什么ConcurrentHashMap是弱一致的
  16. 移动端UI
  17. chrome 调试 ios的 H5 页面
  18. 【bzoj3295】[Cqoi2011]动态逆序对 树套树 线段树套替罪羊树
  19. springboot统一异常处理及返回数据的处理
  20. 微信小程序上传一或多张图片

热门文章

  1. PatentTips - Fast awake from low power mode
  2. OpenGL核心之视差映射
  3. [ES2016] Check if an array contains an item using Array.prototype.includes
  4. 【网络】无法解析服务器的DNS地址?;能登陆QQ,无法打开网页
  5. 设置非ARC
  6. ORACLE中死锁
  7. WPF入门(三)-&gt;几何图形之不规则图形(PathGeometry)
  8. Web前端实践经验总结
  9. 【t004】切割矩阵
  10. dropzone上传文件