■ 비트맵 명도 조정하기

----------------------------------------------------------------------------------------------------

using System;

using System.Drawing;

 

#region 비트맵 명도 조정하기 - AdjustBitmapBrightness(sourceImage, brightness)

 

/// <summary>

/// 비트맵 명도 조정하기

/// </summary>

/// <param name="sourceImage">소스 이미지</param>

/// <param name="brightness">명도</param>

/// <returns>명도 조정 비트맵</returns>

public Bitmap AdjustBitmapBrightness(Image sourceImage, int brightness)

{

    Bitmap targetBitmap = new Bitmap(sourceImage);

    Color  color;

    int    r;

    int    g;

    int    b;

        

    for(int y = 0; y < targetBitmap.Height; y++)

    {

        for(int x = 0; x < targetBitmap.Width; x++)

        {

            color = targetBitmap.GetPixel(x, y);

 

            r = Math.Max(0, Math.Min(255, color.R + brightness));

            g = Math.Max(0, Math.Min(255, color.G + brightness));

            b = Math.Max(0, Math.Min(255, color.B + brightness));

 

            color = Color.FromArgb(r, g, b);

 

            targetBitmap.SetPixel(x, y, color);

        }

    }

 

    return targetBitmap;

}

 

#endregion

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker

댓글을 달아 주세요