첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170
using System.Drawing;

#region 색상 구하기 - GetColor(hue, saturation, luminance)

/// <summary>
/// 색상 구하기
/// </summary>
/// <param name="hue">색조</param>
/// <param name="saturation">채도</param>
/// <param name="luminance">명도</param>
/// <returns>색상</returns>
public Color GetColor(int hue, double saturation, double luminance)
{
    double hueDouble = hue / 360d;
    double red       = 0d;
    double green     = 0d;
    double blue      = 0d;
    double temporary1;
    double temporary2;

    if(luminance == 0d)
    {
        red = green = blue = 0d;
    }
    else
    {
        if(saturation == 0d)
        {
            red = green = blue = luminance;
        }
        else
        {
            temporary2 = ((luminance <= 0.5d) ? luminance * (1d + saturation) : luminance + saturation - (luminance * saturation));
            temporary1 = 2d * luminance - temporary2;

            double[] temporarayArray = new double[] { hueDouble + 1d / 3d, hueDouble, hueDouble - 1d / 3d };
            double[] colorArray      = new double[] { 0d, 0d, 0d };

            for(int i = 0; i < 3; i++)
            {
                if(temporarayArray[i] < 0)
                {
                    temporarayArray[i] += 1d;
                }

                if(temporarayArray[i] > 1)
                {
                    temporarayArray[i] -= 1d;
                }

                if(6d * temporarayArray[i] < 1d)
                {
                    colorArray[i] = temporary1 + (temporary2 - temporary1) * temporarayArray[i] * 6d;
                }
                else if(2d * temporarayArray[i] < 1d)
                {
                    colorArray[i] = temporary2;
                }
                else if(3d * temporarayArray[i] < 2d)
                {
                    colorArray[i] = (temporary1 + (temporary2 - temporary1) * ((2d / 3d) - temporarayArray[i]) * 6d);
                }
                else
                {
                    colorArray[i] = temporary1;
                }
            }

            red   = colorArray[0];
            green = colorArray[1];
            blue  = colorArray[2];
        }
    }

    return Color.FromArgb((int)(255d * red), (int)(255d * green), (int)(255d * blue));
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요