更新时间:2022-09-27 18:47:33
[函数名称]
图像木刻效果函数WoodCutProcess(WriteableBitmap src)
[函数代码]
///<summary>
/// Wood cut process.
///</summary>
///<param name="src">Source image.</param>
///<returns></returns>
publicstaticWriteableBitmap WoodCutProcess(WriteableBitmap src)////17木刻处理
{
if(src!=null )
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap woodcutImage =newWriteableBitmap(w,h);
byte[] temp = src.PixelBuffer.ToArray();
int tempRGB = 0;
for (int i = 0; i < temp.Length; i += 4)
{
tempRGB = (int)((temp[i] + temp[i + 1] + temp[i + 2]) / 3);
temp[i] = (byte)(tempRGB > 122.5 ? 0 : 255);
temp[i + 1] = (byte)(tempRGB > 122.5 ? 0 : 255);
temp[i + 2] = (byte)(tempRGB > 122.5 ? 0 : 255);
tempRGB = 0;
}
Stream sTemp = woodcutImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return woodcutImage;
}
else
{
returnnull;
}
}
[图像效果]