728x90
반응형
728x170
using System.Drawing;
#region 가장 가까운 색상 구하기 - GetNearestColor(colorArray, red, green, blue)
/// <summary>
/// 가장 가까운 색상 구하기
/// </summary>
/// <param name="colorArray">색상 배열</param>
/// <param name="red">빨강색</param>
/// <param name="green">녹색</param>
/// <param name="blue">파랑색</param>
/// <returns>인덱스</returns>
public int GetNearestColor(Color[] colorArray, byte red, byte green, byte blue)
{
int distanceSquared;
int minimumDistanceSquared = 195076; // 255 * 255 + 255 * 255 + 255 * 255 + 1
int bestIndex = 0;
int redDifference;
int greenDifference;
int blueDifference;
for(int i = 0; i < colorArray.Length; i++)
{
redDifference = red - colorArray[i].R;
greenDifference = green - colorArray[i].G;
blueDifference = blue - colorArray[i].B;
distanceSquared = redDifference * redDifference + greenDifference * greenDifference + blueDifference * blueDifference;
if(distanceSquared < minimumDistanceSquared)
{
minimumDistanceSquared = distanceSquared;
bestIndex = i;
}
}
return bestIndex;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 16진수 색상 코드 구하기 (0) | 2015.01.31 |
---|---|
[C#/WINFORM] 색상 정렬 리스트 구하기 (0) | 2015.01.31 |
[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] 16진수 문자열 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] HSL 색상에서 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] 혼합 색상 구하기 (0) | 2015.01.26 |
[C#/WINFORM] 혼합 색상 구하기 (0) | 2015.01.26 |
댓글을 달아 주세요