첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Drawing;

#region 색상 구하기 - GetColor(hexadecimalString)

/// <summary>
/// 색상 구하기
/// </summary>
/// <param name="hexadecimalString">16진수 문자열</param>
/// <returns>색상</returns>
public Color GetColor(string hexadecimalString)
{
    if(string.IsNullOrEmpty(hexadecimalString))
    {
        return Color.Empty;
    }

    if(hexadecimalString.Length != 6)
    {
        return Color.Empty;
    }

    string red   = hexadecimalString.Substring(0, 2);
    string green = hexadecimalString.Substring(2, 2);
    string blue  = hexadecimalString.Substring(4, 2);

    int redInteger;

    try
    {
        redInteger = Convert.ToInt32(red, 16);                   
    }
    catch
    {
        return Color.Empty;
    }

    int greenInteger;

    try
    {
        greenInteger = Convert.ToInt32(green, 16);
    }
    catch
    {
        return Color.Empty;
    }

    int blueInteger;

    try
    {
        blueInteger = Convert.ToInt32(blue, 16);
    }
    catch
    {
        return Color.Empty;
    }

    return Color.FromArgb(redInteger, greenInteger, blueInteger);
}

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

댓글을 달아 주세요