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

来源:互联网 发布:python爬虫 pdf 编辑:程序博客网 时间:2024/04/29 05:19


[函数名称]

图像木刻效果函数WoodCutProcess(WriteableBitmap src)

[函数代码]

       ///<summary>

       /// Wood cut process.

       ///</summary>

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

       ///<returns></returns>

       publicstaticWriteableBitmap WoodCutProcess(WriteableBitmap src)////17木刻处理

       {

           if(src!=null )

           {

           int w = src.PixelWidth;

           int h = src.PixelHeight;

           WriteableBitmap woodcutImage =newWriteableBitmap(w,h);

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

           int tempRGB = 0;

           for (int i = 0; i < temp.Length; i += 4)

           {

               tempRGB = (int)((temp[i] + temp[i + 1] + temp[i + 2]) / 3);

               temp[i] = (byte)(tempRGB > 122.5 ? 0 : 255);

               temp[i + 1] = (byte)(tempRGB > 122.5 ? 0 : 255);

               temp[i + 2] = (byte)(tempRGB > 122.5 ? 0 : 255);

               tempRGB = 0;

           }

           Stream sTemp = woodcutImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

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

           return woodcutImage;

           }

           else

           {

               returnnull;

           }  

       }

[图像效果]

0 0
原创粉丝点击