映像濾鏡藝術---Glow Filter發光濾鏡,---glowfilter

來源:互聯網
上載者:User

映像濾鏡藝術---Glow Filter發光濾鏡,---glowfilter

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

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.