原文:
图像滤镜艺术---暗调滤镜
本文介绍暗调滤镜的实现过程,这个滤镜主要是呈现一种暗调,对比度明显的效果,原理很简单,公式如下:
newR = R*R/255;
newG = G*G/255;
newB = B*B/255;
实现代码如下:
private Bitmap FilterProcess(Bitmap a)
{
Bitmap srcBitmap = new Bitmap(a);
int w = srcBitmap.Width;
int h = srcBitmap.Height;
System.Drawing.Imaging.BitmapData srcData = srcBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
byte* pSrc = (byte*)srcData.Scan0;
int offset = srcData.Stride - w * 4;
int r, g, b;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
b = pSrc[0];
g = pSrc[1];
r = pSrc[2];
pSrc[2] = (byte)(r * r / 255);
pSrc[1] = (byte)(g * g / 255);
pSrc[0] = (byte)(b * b / 255);
pSrc += 4;
}
pSrc += offset;
}
srcBitmap.UnlockBits(srcData);
return srcBitmap;
}
效果如下:
原图
暗调效果图
最后,放上一个完整的C#/C程序DEMO下载链接:http://www.zealpixel.com/forum.php?mod=viewthread&tid=79&extra=page%3D1