Win8Metro(C#)数字图像处理--2.5图像亮度调整

原文:Win8Metro(C#)数字图像处理--2.5图像亮度调整



2.5图像亮度调整函数

[函数名称]

  图像亮度调整函数BrightnessAdjustProcess(WriteableBitmap src, intbrightnessValue)

Win8Metro(C#)数字图像处理--2.5图像亮度调整

[函数代码]

       ///<summary>

       /// Bright adjust process.

       ///</summary>

       ///<param name="src">Source image.</param>

       ///<param name="brightnessValue">Brightness value, from -255 to 255.</param>

       ///<returns></returns>

       publicstaticWriteableBitmap BrightnessAdjustProcess(WriteableBitmap src, int brightnessValue)////5亮度调整

       {

           if(src!=null )

           {

           int w = src.PixelWidth;

           int h = src.PixelHeight;

           WriteableBitmap brightImage =newWriteableBitmap(w,h);

           byte[] temp = src.PixelBuffer.ToArray();

           for (int i = 0; i < temp.Length; i += 4)

           {

               temp[i] = (byte)(((brightnessValue + temp[i]) > 255 ? 255 : (brightnessValue + temp[i])) < 0 ? 0 : ((brightnessValue + temp[i]) > 255 ? 255 : (brightnessValue + temp[i])));

               temp[i+1] = (byte)(((brightnessValue + temp[i+1]) > 255 ? 255 : (brightnessValue + temp[i+1])) < 0 ? 0 : ((brightnessValue + temp[i+1]) > 255 ? 255 : (brightnessValue + temp[i+1])));

               temp[i+2] = (byte)(((brightnessValue + temp[i+2]) > 255 ? 255 : (brightnessValue + temp[i+2])) < 0 ? 0 : ((brightnessValue + temp[i+2]) > 255 ? 255 : (brightnessValue + temp[i+2])));

           }

           Stream sTemp = brightImage.PixelBuffer.AsStream();

           sTemp.Seek(0, SeekOrigin.Begin);

           sTemp.Write(temp, 0, w * 4 * h);

           return brightImage;

           }

           else

           {

               returnnull;

           }  

       }

Win8Metro(C#)数字图像处理--2.5图像亮度调整


 
上一篇:IT国产化加速,迎接IT国产时代


下一篇:企业云存储:为什么中大型企业都偏爱自建企业云?