天天看點

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;

h = src.PixelHeight;

           WriteableBitmap

mirrorImage =newWriteableBitmap(w,h);

           byte[]

temp = src.PixelBuffer.ToArray();

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 *

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

               }

           }         

           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圖像垂直鏡像

繼續閱讀