[函数名称]
图像曝光函数ExposureProcess(WriteableBitmap src,int exposureValue)
[函数代码]
/// <summary>
/// Exposure process.
/// </summary>
/// <param name="src">Source image.</param>
/// <param name="exposureValue">To adjust exposure lavel, from 0 to 255.</param>
/// <returns></returns>
public static WriteableBitmap ExposureProcess(WriteableBitmap src,int exposureValue)////35图像曝光
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap exposureImage = new WriteableBitmap(w, h);
int r=0,g=0,b=0;
byte[] temp = src.PixelBuffer.ToArray();
for (int i = 0; i < temp.Length; i += 4)
{
byte tempByte = (byte)((int)(temp[i] * 0.114 + temp[i + 1] * 0.587 + temp[i + 2] * 0.299));
b = temp[i];
g = temp[i + 1];
r = temp[i + 2];
if (tempByte < 128)
{
temp[i] = (byte)(255 - b);
temp[i + 1] = (byte)(255 - g);
temp[i + 2] = (byte)(255 - r);
}
}
Stream sTemp = exposureImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return exposureImage;
}
else
{
return null;
}
}
[图像效果]