Win8Metro(C#)数字图像处理--2.3图像反色

原文:Win8Metro(C#)数字图像处理--2.3图像反色


[函数名称]

图像反色函数ContraryProcess(WriteableBitmap src)

[算法说明]

    反色公式如下:       P'(x,y) = 255 - P(x,y);

    P'(x,y)为反色后的像素值,P(x,y)是原始像素值。

[函数代码]

       ///<summary>

       /// Contrary process.

       ///</summary>

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

       ///<returns></returns>

 publicstaticWriteableBitmap ContraryProcess(WriteableBitmap src)////3反色处理

       {

           if(src!=null )

           {

           int w = src.PixelWidth;

           int h = src.PixelHeight;

           WriteableBitmap contraryImage =newWriteableBitmap(w, h);

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

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

           {

               temp[i] = (byte)(255 - temp[i]);

               temp[i + 1] = (byte)(255 - temp[i + 1]);

               temp[i + 2] = (byte)(255 - temp[i + 2]);

           }

           Stream sTemp = contraryImage.PixelBuffer.AsStream();

           sTemp.Seek(0,SeekOrigin.Begin);

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

           return contraryImage;

           }       

           else

           {

               returnnull;

           }  

       }

Win8Metro(C#)数字图像处理--2.3图像反色


 

上一篇:slf4j 日志接口 统一


下一篇:mongodb对数组元素及内嵌文档进行增删改查操作(转)