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

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



[函数名称]

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

[函数代码]

       ///

       /// Wood cut process.

       ///

       ///Source image.

       ///

       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;

           }  

       }

[图像效果]

你可能感兴趣的:(Win8Metro(C#)数字图像处理--2.17图像木刻效果)