[函数名称]
图像反色函数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;
}
}