图像滤镜艺术---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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Trent1985

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值