原文: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. 【hdu 2955】Robberies

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  2. erlang局域网内节点通信——艰难四步曲

    http://blog.chinaunix.net/uid-22566367-id-382011.html 在Programming Erlang这本书中,在写到第十章中,主要实现的是不同节点之间的通 ...

  3. java phoenix 连接hbase

    <dependency> <groupId>org.apache.phoenix</groupId> <artifactId>phoenix-core& ...

  4. Gson的使用(JsonObject)

    在Java开发互联网应用系统的过程中,数据的传递与转换是经常使用的,我在开发的过程中用的最多的是google的Gson,现就其使用的过程中的注意点做一个总结(当然首先要先去下载Gson的jar包,附件 ...

  5. FreeBSD中的SYSINIT框架【转】

    SYSINIT是一个通用的调用排序与分别执行机制的框架.FreeBSD目前使用它来进行内核的动态初始化.SYSINIT使得FreeBSD的内核各子系统可以在内核或模块动态加载链接时被重整.添加.删除. ...

  6. android:layout_gravity和android:gravity属性的差别

    gravity的中文意思就是"重心",就是表示view横向和纵向的停靠位置 android:gravity:是对view控件本身来说的,是用来设置view本身的文本应该显示在vie ...

  7. Jsp bug_001

    报错: The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解 ...

  8. Delphi 中的字符串(还解释了shortstring)good

    一.Delphi 2009 之前的字符串(不支持 Unicode): Delphi 2009 之前的字符串分为 3 种:ShortString.AnsiString.WideString. [Shor ...

  9. [Scikit-Learn] - 数据预处理 - 缺失值(Missing Value)处理

    reference : http://www.cnblogs.com/chaosimple/p/4153158.html 关于缺失值(missing value)的处理 在sklearn的prepro ...

  10. Java 9 特性

    Java 8 发布三年多之后,已经于在2017年9月21日发布了. 你可能已经听说过 Java 9 的模块系统,但是这个新版本还有许多其它的更新. 这里有九个令人兴奋的新功能. 1. Java 平台级 ...