本文主要是介绍Win8Metro(C#)数字图像处理--2.32图像曝光算法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
[函数名称]
图像曝光函数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;
}
}
[图像效果]
这篇关于Win8Metro(C#)数字图像处理--2.32图像曝光算法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!