影像濾鏡藝術----Brannan濾鏡

weixin_34221276發表於2018-03-13
原文:影像濾鏡藝術----Brannan濾鏡

    作為第一篇文章,本人將介紹Instagram中Brannan 濾鏡的實現過程,當然,是自己的模擬而已,結果差異敬請諒解。

    先看下效果圖:

1 PS實現步驟:

1.1 開啟測試影像,複製圖層,命名為圖層a

1.2 對圖層a進行去色操作,然後,開啟色階-綠色-調整如下:

1.3對當前圖層a選擇圖層混合模式-濾色;

1.4新建圖層b,填充顏色RGB(36,1, 34),選擇圖層混合模式-柔光,不透明度60%

1.5新建圖層c,填充顏色RGB(253,253,241),選擇圖層混合模式-正片疊底:

1.6合併所有圖層,即可得到相應的效果圖了;

2,程式實現:

<span style="font-size:14px;">public static Bitmap DoGrayEffect(Bitmap srcBitmap, int pxMode)
{
    Bitmap src = new Bitmap(srcBitmap);
    int w = src.Width;
    int h = src.Height;
    PixelFormat format = (pxMode == 0 ? PixelFormat.Format24bppRgb : PixelFormat.Format32bppArgb);
    BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, format);
    Desaturate((byte*)srcData.Scan0, w, h, srcData.Stride, pxMode);
    src.UnlockBits(srcData);
    return src;
}</span>
<span style="font-size:14px;"> //色階調整
public static Bitmap DoLevelAdjust(Bitmap srcBitmap, int DestChannel, int InputLeftLimit, int InputMiddle, int InputRightLimit, int OutputLeftLimit, int OutputRightLimit, int pxMode)
{
    Bitmap src = new Bitmap(srcBitmap);
    int w = src.Width;
    int h = src.Height;
    PixelFormat format = (pxMode == 0 ? PixelFormat.Format24bppRgb : PixelFormat.Format32bppArgb);
    BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, format);
    LevelAdjust((byte*)srcData.Scan0, w, h, srcData.Stride, DestChannel, InputLeftLimit, InputMiddle, InputRightLimit, OutputLeftLimit, OutputRightLimit, pxMode);
    src.UnlockBits(srcData);
    return src;
}</span>
<span style="font-size:14px;">//圖層混合模式
        public static Bitmap DoEffect(Bitmap srcBitmap, Bitmap mxBitmap, int pxMode, int effectMode)
        {
            Bitmap src = new Bitmap(srcBitmap);
            Bitmap mx = new Bitmap(mxBitmap);
            int w = src.Width;
            int h = src.Height;
            PixelFormat format = (pxMode == 0 ? PixelFormat.Format24bppRgb : PixelFormat.Format32bppArgb);
            BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, format);
            BitmapData mxData = mx.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, format);
            DoSpecialEffect((byte*)srcData.Scan0, (byte*)mxData.Scan0, w, h, srcData.Stride, pxMode, effectMode);
            src.UnlockBits(srcData);
            mx.UnlockBits(mxData);
            return src;
        }
        //單色圖層混合模式
        public static Bitmap DoSingleColorEffect(Bitmap srcBitmap, int r, int g, int b, int pxMode, int effectMode)
        {
            Bitmap src = new Bitmap(srcBitmap);
            int w = src.Width;
            int h = src.Height;
            PixelFormat format = (pxMode == 0 ? PixelFormat.Format24bppRgb : PixelFormat.Format32bppArgb);
            BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, format);
            byte* p = (byte*)srcData.Scan0;
            int seg = (pxMode == 0 ? 3 : 4);
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    DoPixelEffect(p, r, g, b, effectMode);
                    p += seg;
                }
                p += srcData.Stride - w * seg;
            }
            src.UnlockBits(srcData);
            return src;
        }</span>
<span style="font-size:14px;">        //Brannan 濾鏡
        public static Bitmap BrannanFilter(Bitmap srcBitmap, int pxMode)
        {
            Bitmap temp = DoGrayEffect(srcBitmap, 0);//去色
            Bitmap leBmp = DoLevelAdjust(temp, 2, 0, 128, 232, 0, 250, 0);//綠色色階調整
            Bitmap filterBmp = DoEffect(srcBitmap, leBmp, 0, (int)EffectMode.MODE_FILTERCOLOR);//濾色
            temp = DoSingleColorEffect(filterBmp, 22, 1, 20, 0, (int)EffectMode.MODE_SMOOTHLIGHT);//柔化
            temp = DoSingleColorEffect(temp, 253, 253, 241, 0, (int)EffectMode.MODE_MULTIPLY);//正片疊底
            return temp;
        }</span>


PSD檔案及C程式碼DEMO免費下載連結:點選開啟連結

 

最後,分享一個專業的影像處理網站(微畫素),裡面有很多原始碼下載:

 

相關文章