怀旧风格滤镜

最后更新于:2022-04-01 06:45:57

怀旧风格滤镜 本文介绍一款怀旧风格滤镜特效的代码实现,这个滤镜效果跟前面我们介绍的老照片滤镜效果相比,听起来感觉没太大差,实际上老照片不仅 有怀旧的风格,更多了一些怀旧的痕迹,比如照片的褶皱,裂纹等等,而怀旧风格,只是一种发黄的颜色风格而已。 下面给出怀旧风格的代码: ~~~ 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 b = 0, g = 0, r = 0, gray = 0; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { b = pSrc[0]; g = pSrc[1]; r = pSrc[2]; gray = (272 * r + 534 * g + 131 * b) / 1000; pSrc[0] = (byte)(Math.Min(255, Math.Max(0, gray))); gray = (349 * r + 686 * g + 168 * b) / 1000; pSrc[1] = (byte)(Math.Min(255, Math.Max(0, gray))); gray = (393 * r + 769 * g + 189 * b) / 1000; pSrc[2] = (byte)(Math.Min(255, Math.Max(0, gray))); pSrc += 4; } pSrc += offset; } srcBitmap.UnlockBits(srcData); return srcBitmap; } ~~~ 代码很短,也很简单,效果却还 不错,下面看下效果: [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-05_568b3321ba97c.jpg)](http://www.zealpixel.com/data/attachment/portal/201508/12/221721k2rrntdrodprddc8.jpg) 原图 [![](https://docs.gechiui.com/gc-content/uploads/sites/kancloud/2016-01-05_568b3321d6643.png)](http://www.zealpixel.com/data/attachment/portal/201508/12/221720f6egu7w297eu29gy.png) 怀旧风格效果 最后,给出一个完整的程序DEMO下载链接:[http://www.zealpixel.com/thread-77-1-1.html](http://www.zealpixel.com/thread-77-1-1.html) DEMO中包含C#/C两种语言接口实现,希望大家喜欢!
';