且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Win8Metro(C#)数字图像处理--2.20图像垂直镜像

更新时间:2022-09-27 18:43:04

原文:Win8Metro(C#)数字图像处理--2.20图像垂直镜像



[函数名称]

图像垂直镜像函数MirrorYProcess(WriteableBitmap src)

Win8Metro(C#)数字图像处理--2.20图像垂直镜像

[函数代码]

       ///<summary>

       /// Vertical mirror process.

       ///</summary>

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

       ///<returns></returns>

       publicstaticWriteableBitmap MirrorYProcess(WriteableBitmap src)////20垂直镜像

       {

           if(src!=null )

           {

           int w = src.PixelWidth;

           int h = src.PixelHeight;

           WriteableBitmap mirrorImage =newWriteableBitmap(w,h);

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

           byte[] tempMask =newbyte[w * h * 4];

           for (int i = 0; i < w; i++)

           {

               for (int j = 0; j < h; j++)

               {

                   tempMask[i * 4 + j * w * 4] = temp[i * 4 + (h - 1 - j) * w * 4];

                   tempMask[i * 4 + 1 + j * w * 4] = temp[i * 4 + 1 + (h - 1 - j) * w * 4];

                   tempMask[i * 4 + 2 + j * w * 4] = temp[i * 4 + 2 + (h - 1 - j) * w * 4];

                   tempMask[i * 4 + 3 + j * w * 4] = temp[i * 4 + 3 + (h - 1 - j) * w * 4];

               }

           }         

           Stream sTemp = mirrorImage.PixelBuffer.AsStream();

           sTemp.Seek(0, SeekOrigin.Begin);

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

           return mirrorImage;

           }

           else

           {

               returnnull;

           }            

       }

[图像效果]

Win8Metro(C#)数字图像处理--2.20图像垂直镜像