原文: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. Java中的equals比较,小坑一个

    最近工作中,经常需要比较2个对象的值.有个问题经常遇到,就是下面的2种情况. public static void main(String[] args) { Integer a =11; Objec ...

  2. linux使用.rpm包安装mysql

    一:下载mysql的.rpm安装包 点击链接查看下载教程:点击打开链接 二:创建目录,上传文件 创建mysql目录:# mkdir mysql 进入目录:# cd mysql 将下载好的MySQL-s ...

  3. Android ReentrantLock

    synchronized原语和ReentrantLock在一般情况下没有什么区别,但是在非常复杂的同步应用中,请考虑使用ReentrantLock,特别是遇到下面2种需求的时候. 1.某个线程在等待一 ...

  4. 【hdu 1536】S-Nim

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

  5. 76个值得你注意的erlang编程习惯

    http://www.tuicool.com/articles/ZNzuyu 前言 学习Erlang的时候在书的留白处随手记录了一些东西,还有一些记录在了demo的注释里面,今天抽时间整理出来了一部分 ...

  6. 【hdu2825】ac自动机 + 状压dp

    传送门 题目大意: 给你一些密码片段字符串,让你求长度为n,且至少包含k个不同密码片段串的字符串的数量. 题解: 因为密码串不多,可以考虑状态压缩 设dp[i][j][sta]表示长为i的字符串匹配到 ...

  7. kindeditor 4 指定生成文件的时间日期/动态获取My97的时间

    最近后台要求要指定上传附件的时间日期,编辑器是kindeditor,仔细研究后发现可以借助clickToolbar事件,传递时间到后台,但是中途发现传递的时间总是初始化my97的时间,改变后的时间只有 ...

  8. 【43.75%】【codeforces 688E】The Values You Can Make

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. OpenVZ安装指南,一种操作系统级别的虚拟化技术

    鼎鼎大名的 OpenVZ 谁不知道?在主机行业被使用(滥用)很多年,依然在茁壮发展.作为一种操作系统级别的虚拟化技术,运行 OpenVZ 没有硬性的硬件要求.OpenVZ 能够创建被称为容器(cont ...

  10. Method for finding shortest path to destination in traffic network using Dijkstra algorithm or Floyd-warshall algorithm

    A method is presented for finding a shortest path from a starting place to a destination place in a ...