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
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] RGB 구하기 (0) | 2015.01.31 |
---|---|
[C#/WINFORM] BGRA 구하기 (0) | 2015.01.31 |
[C#/WINFORM] RGBA 구하기 (0) | 2015.01.31 |
[C#/WINFORM] 가장 가까운 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] 투명 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] HSL 색상에서 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] 혼합 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] 혼합 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] HSL 구하기 (0) | 2015.01.26 |
[C#/WINFORM] CMYK를 CMY로 변환하기 (0) | 2015.01.26 |
댓글을 달아 주세요