原文: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. [React Router v4] Use Regular Expressions with Routes

    We can use regular expressions to more precisely define the paths to our routes in React Router v4. ...

  2. php正则怎么使用(最全最细致)

    php正则怎么使用(最全最细致) 一.总结 一句话总结: 1.正则中的行定位符是什么? 解答:(^与$) 2.正则中什么时候用行定位符? 解答:如"^de",表示以de开头的字符串 ...

  3. Eclipse使用异常——tomcat启动

    Eclipse使用异常--tomcat启动 一:问题描写叙述 Eclipse刚上手.非常多地方与Myeclipse不一样的地方.比方tomcat的使用.真心的蛋疼. 环境:JDK7.TOMCAT7.E ...

  4. zzuli OJ 1129: 第几天

    Description 你知道.2012-1-1是该年的第1天.而9999-9-9呢?给你一个详细的日期,计算该日期是该年的第几天. Input 输入一个日期.格式为:Year-month-day.y ...

  5. 微信Android终端SDK新手使用指南

    1.申请你的AppID 请到 开发者应用登记页面 进行登记,登记并选择移动应用进行设置后,将获得AppID,可立即用于开发.但应用登记完成后还需要提交审核,只有审核通过的应用才能正式发布使用. 2.下 ...

  6. 怎样获取android手机联系人并按字母展示(三)

    假设获取contact的头像信息并展示: 怎样依据photoId来获取bitmap: public static Bitmap getContactPhoto(Context context, lon ...

  7. google地图API的简单使用

    <div id="contact_container" style="width:700px;height:600px;"></div> ...

  8. sklearn 下距离的度量 —— sklearn.metrics

    1. pairwise from sklearm.metrics.pairwise import pairwise_distance 计算一个样本集内部样本之间的距离: D = np.array([n ...

  9. ElasticSearch的基本用法与集群搭建 good

    一.简介 ElasticSearch和Solr都是基于Lucene的搜索引擎,不过ElasticSearch天生支持分布式,而Solr是4.0版本后的SolrCloud才是分布式版本,Solr的分布式 ...

  10. 接口测试——fiddler对soapui请求返回信息抓取

    原文:接口测试——fiddler对soapui请求返回信息抓取 背景:接口测试的时候,需要对接口的请求和返回信息进行查阅或者修改请求信息,可利用fiddler抓包工具对soapui的请求数据进行抓取或 ...