圖像濾鏡藝術---懷舊風格濾鏡

原文: 圖像濾鏡藝術---懷舊風格濾鏡

懷舊風格濾鏡 html

本文介紹一款懷舊風格濾鏡特效的代碼實現,這個濾鏡效果跟前面咱們介紹的老照片濾鏡效果相比,聽起來感受沒太大差,實際上老照片不只 有懷舊的風格,更多了一些懷舊的痕跡,好比照片的褶皺,裂紋等等,而懷舊風格,只是一種發黃的顏色風格而已。
下面給出懷舊風格的代碼:
 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;
        }
代碼很短,也很簡單,效果卻還 不錯,下面看下效果:

原圖ide

懷舊風格效果.net

最後,給出一個完整的程序DEMO下載連接:http://www.zealpixel.com/thread-77-1-1.htmlorm

DEMO中包含C#/C兩種語言接口實現,但願你們喜歡!htm

相關文章
相關標籤/搜索