原文:Win8Metro(C#)数字图像处理--2.15图像霓虹效果



[函数名称]

图像霓虹效果函数NeonProcess(WriteableBitmap src)

上述公式进行开方即可。

[函数代码]

       ///<summary>

       /// Neon process.

       ///</summary>

       ///<param name="src">Source image.</param>

       ///<returns></returns>

       publicstaticWriteableBitmap NeonProcess(WriteableBitmap src)////15霓虹处理

       {

           if(src!=null )

           {

           int w = src.PixelWidth;

           int h = src.PixelHeight;

           WriteableBitmap neonImage =newWriteableBitmap(w, h);

           byte[] temp = src.PixelBuffer.ToArray();

           byte[] tempMask = (byte[])temp.Clone();

           int b = 0, g = 0, r = 0;

           for (int j = 1; j < h - 1; j++)

           {

               for (int i = 4; i < w * 4 - 4; i += 4)

               {

                   if (i == 0 || i == w - 4 || j == 0 || j == h - 1)

                   {

                       temp[i + j * w * 4] = (byte)0;

                       temp[i + 1 + j * w * 4] = (byte)0;

                       temp[i + 2 + j * w * 4] = (byte)0;

                   }

                   else

                   {

                       b = (int)Math.Sqrt((tempMask[i + j * w * 4] - tempMask[i + 4 + j * w * 4]) * (tempMask[i + j * w * 4] - tempMask[i + 4 + j * w * 4])

                           + (tempMask[i + j * w * 4] - tempMask[i + (j + 1) * w * 4]) * (tempMask[i + j * w * 4] - tempMask[i + (j + 1) * w * 4]));

                       g = (int)Math.Sqrt((tempMask[i + 1 + j * w * 4] - tempMask[i + 4 + 1 + j * w * 4]) * (tempMask[i + 1 + j * w * 4] - tempMask[i + 4 + 1 + j * w * 4])

                           + (tempMask[i + 1 + j * w * 4] - tempMask[i + 1 + (j + 1) * w * 4]) * (tempMask[i + 1 + j * w * 4] - tempMask[i + 1 + (j + 1) * w * 4]));

                       r = (int)Math.Sqrt((tempMask[i + 2 + j * w * 4] - tempMask[i + 4 + 2 + j * w * 4]) * (tempMask[i + 2 + j *w * 4] - tempMask[i + 4 + 2 + j * w * 4])

                           + (tempMask[i + 2 + j * w * 4] - tempMask[i + 2 + (j + 1) * w * 4]) * (tempMask[i + 2 + j * w * 4] - tempMask[i + 2 + (j + 1) * w * 4]));

                       temp[i + j * w * 4] = (byte)(b > 0 ? (b < 255 ? b : 255) : 0);

                       temp[i + 1 + j * w * 4] = (byte)(g > 0 ? (g < 255 ? g : 255) : 0);

                       temp[i + 2 + j * w * 4] = (byte)(r > 0 ? (r < 255 ? r : 255) : 0);

                   }

                   b = 0; g = 0; r = 0;

               }

           }

           Stream sTemp = neonImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

           sTemp.Write(temp, 0, w * 4 * h);

           return neonImage;

           }

           else

           {

               returnnull;

           }  

       }

[图像效果]

Win8Metro(C#)数字图像处理--2.15图像霓虹效果的更多相关文章

  1. Win8Metro(C#)数字图像处理--2.17图像木刻效果

    原文:Win8Metro(C#)数字图像处理--2.17图像木刻效果  [函数名称] 图像木刻效果函数WoodCutProcess(WriteableBitmap src) [函数代码] ///& ...

  2. Win8Metro(C#)数字图像处理--2.3图像反色

    原文:Win8Metro(C#)数字图像处理--2.3图像反色 [函数名称] 图像反色函数ContraryProcess(WriteableBitmap src) [算法说明]     反色公式如下: ...

  3. Win8Metro(C#)数字图像处理--2.33图像非线性变换

    原文:Win8Metro(C#)数字图像处理--2.33图像非线性变换  [函数名称] 图像非线性变换函数NonlinearTransformProcess(WriteableBitmap src ...

  4. Win8Metro(C#)数字图像处理--2.32图像曝光算法

    原文:Win8Metro(C#)数字图像处理--2.32图像曝光算法  [函数名称] 图像曝光函数ExposureProcess(WriteableBitmap src,int exposureV ...

  5. Win8Metro(C#)数字图像处理--2.27图像加法运算

    原文:Win8Metro(C#)数字图像处理--2.27图像加法运算  [函数名称] 图像加法函数AddProcess(WriteableBitmap src, WriteableBitmap a ...

  6. Win8Metro(C#)数字图像处理--2.28图像乘法运算

    原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算  [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...

  7. Win8Metro(C#)数字图像处理--2.29图像除法运算

    原文:Win8Metro(C#)数字图像处理--2.29图像除法运算  [函数名称] 图像除法函数DivisionProcess(WriteableBitmap src, WriteableBit ...

  8. Win8Metro(C#)数字图像处理--2.26图像减法

    原文:Win8Metro(C#)数字图像处理--2.26图像减法  [函数名称] 图像减法函数SubtractionProcess(WriteableBitmap src, WriteableBi ...

  9. Win8Metro(C#)数字图像处理--2.19图像水平镜像

    原文:Win8Metro(C#)数字图像处理--2.19图像水平镜像  [函数名称] 图像水平镜像函数MirrorXProcess(WriteableBitmap src) [函数代码]      ...

随机推荐

  1. ios app初始化和数据迁移的设计思路

    整体思路 一般app启动之后,都有一个初始化的过程. 此外兴许app升级,还须要考虑数据迁移.所以初始化和数据迁移的框架.在初期的版本号就要考虑好 总结一下我们的app採取的方案: 1.在持久化的文件 ...

  2. 小强的HTML5移动开发之路(43)——JqueryMobile页眉、工具栏和标签栏导航

    一.页眉 1.添加页眉和页脚 <div data-role="header"> <h1>第 1 页</h1> </div> < ...

  3. 【codeforces 757C】Felicity is Coming!

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. erlang lists

    http://blog.csdn.net/dp0304/article/details/7590233 一,带函数Pred1, all(Pred, List) -> boolean()如果Lis ...

  5. 三次握手、四次握手、backlog

    TCP:三次握手.四次握手.backlog及其他   TCP是什么 首先看一下OSI七层模型: 然后数据从应用层发下来,会在每一层都加上头部信息进行封装,然后再发送到数据接收端,这个基本的流程中每个数 ...

  6. 改变事件绑定的this的问题

    以标准的DOM2级事件为例,第二个参数是一个函数,咱们改成bind,看看之后的this是啥. <!DOCTYPE html> <html lang="en"> ...

  7. JScript分割字符串

    作者:朱金灿 来源:http://blog.csdn.net/clever101 不废话了,直接用代码说明吧: try { var ss = new Array(); var str="12 ...

  8. Android——Intent详解

    Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重要. 一.什么是Intent 1.Intent的概念: Android中提供了Intent机制来协助应用间的交互与 ...

  9. 分享 WebBrowser显示Html内容3点细节技巧,解决刷新后空白

    直接显示Html内容,不像直接导航网址容易处理: 问题:按微软的控件属性提示,可以用WebBrowser.DocumentText 属性赋值 ,但是这种赋值,只是首次有效,后续切换都没啥作用. 下面给 ...

  10. Windows下静态编译Qt4

    既然是静态编译,那就要编译出来的程序不信赖于任何dll文件.首先下载qt-win-opensource-4.7.4-mingw.exe: http://get.qt.nokia.com/qt/sour ...