本文共 977 字,大约阅读时间需要 3 分钟。
[函数名称]
图像垂直镜像函数MirrorYProcess(WriteableBitmap src)
[函数代码]
///<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;
}
}
[图像效果]