[函数名称]
图像水平镜像函数MirrorXProcess(WriteableBitmap src)
[函数代码]
///<summary>
/// Horizontal mirror process.
///</summary>
///<param name="src">Source image.</param>
///<returns></returns>
publicstaticWriteableBitmap MirrorXProcess(WriteableBitmap src)////19水平镜像
{
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 j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
tempMask[i * 4 + j * w * 4] = temp[(w - 1 - i) * 4 + j * w * 4];
tempMask[i * 4 + 1 + j * w * 4] = temp[(w - 1 - i) * 4 + 1 + j * w * 4];
tempMask[i * 4 + 2 + j * w * 4] = temp[(w - 1 - i) * 4 + 2 + j * w * 4];
tempMask[i * 4 + 3 + j * w * 4] = temp[(w - 1 - i) * 4 + 3 + j * w * 4];
}
}
Stream sTemp = mirrorImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(tempMask, 0, w * 4 * h);
return mirrorImage;
}
else
{
returnnull;
}
}
[图像效果]