728x90
반응형
728x170
using System.Drawing;
private const int HISTOGRAM_BITMAP_WIDTH = 256;
private const int HISTOGRAM_BITMAP_HEIGHT = 200;
#region 히스토그램 비트맵 구하기 - GetHistogramBitmap(sourceArray, foregroundColor, backgroundColor)
/// <summary>
/// 히스토그램 비트맵 구하기
/// </summary>
/// <param name="sourceArray">소스 배열</param>
/// <param name="foregroundColor">전경색</param>
/// <param name="backgroundColor">배경색</param>
/// <returns>히스토그램 비트맵</returns>
public Bitmap GetHistogramBitmap(int[,] sourceArray, Color foregroundColor, Color backgroundColor)
{
int width = sourceArray.GetUpperBound(1) + 1;
int height = sourceArray.GetUpperBound(0) + 1;
int[] histogramArray = new int[256];
int maximumCount = 0;
Bitmap bitmap = new Bitmap(HISTOGRAM_BITMAP_WIDTH, HISTOGRAM_BITMAP_HEIGHT);
Graphics graphics = Graphics.FromImage(bitmap);
histogramArray.Initialize();
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
histogramArray[sourceArray[y, x]]++;
}
}
for(int i = 0; i < 256; i++)
{
if(histogramArray[i] > maximumCount)
{
maximumCount = histogramArray[i];
}
}
graphics.Clear(backgroundColor);
Pen pen = new Pen(foregroundColor);
for(int x = 0; x < HISTOGRAM_BITMAP_WIDTH; x++)
{
double barHeight = (double)histogramArray[x] * (HISTOGRAM_BITMAP_HEIGHT - 1) / (double)maximumCount;
graphics.DrawLine(pen, x, HISTOGRAM_BITMAP_HEIGHT - (int)barHeight, x, 200);
}
graphics.DrawRectangle(Pens.Black, 0, 0, bitmap.Width - 1, bitmap.Height - 1);
return bitmap;
}
#endregion
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] CheckedListBox 클래스 : 마우스 드래그 항목 체크하기 (0) | 2015.11.05 |
---|---|
[C#/WINFORM] CheckedListBox 클래스 : 데이터 바인딩 하기 (0) | 2015.11.05 |
[C#/WINFORM] TextBox 클래스 : 숫자 텍스트 박스 만들기 (0) | 2015.10.06 |
[C#/WINFORM] TextBox 클래스 : 워터마크 문자열 표시하기 (0) | 2015.09.02 |
[C#/WINFORM] 문자열 너비 구하기 (0) | 2015.09.02 |
[C#/WINFORM] 비트맵 설정하기 (0) | 2015.06.19 |
[C#/WINFORM] 비트맵 배열 구하기 (0) | 2015.06.19 |
[C#/WINFORM] 회색조 비트맵 설정하기 (0) | 2015.06.15 |
[C#/WINFORM] 회색조 비트맵 배열 구하기 (0) | 2015.06.15 |
[C#/WINFORM] 비트맵 경계선 설정하기 (0) | 2015.06.13 |
댓글을 달아 주세요