⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histogram.cpp

📁 图像处理软件,功能比较基础
💻 CPP
字号:
// Histogram.cpp : implementation file
//

#include "stdafx.h"
#include "linjunjuan.h"
#include "Histogram.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Histogram dialog


Histogram::Histogram(CWnd* pParent /*=NULL*/)
	: CDialog(Histogram::IDD, pParent)
{
	flagHis=FALSE;
	threshold=0;
	//{{AFX_DATA_INIT(Histogram)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void Histogram::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Histogram)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Histogram, CDialog)
	//{{AFX_MSG_MAP(Histogram)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Histogram message handlers

void Histogram::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
//	RECT rect;
//	int *Data,max=0;
//	Data=HistoGarm(Image,&cx,&cy);
	//=========归一化便于显示==============
//	for (int k=0;k<256;k++)
//	{
//		if (Data[k]>max)
//			max=Data[k];
//	}
//	for (k=0;k<256;k++)
//		Data[k]=Data[k]*150/max;		
	//====================================
//	MoveToEx(dc.GetSafeHdc,5,154,NULL);
////	LineTo(dc.GetSafeHdc,261,154);
//	MoveToEx(dc.GetSafeHdc,5,154,NULL);
//	LineTo(hDC,5,4);
//	for (int i=0;i<256;i++)
//	{
//		MoveToEx(dc.GetSafeHdc,i+6,154,NULL);
//		LineTo(dc.GetSafeHdc,i+6,154-Data[i]);
//	}
	int max=0;
	dc.MoveTo(45,174);
	dc.LineTo(301,174);
	dc.MoveTo(45,174);
	dc.LineTo(45,24);
	dc.TextOut(45,180,"0");
	dc.TextOut(301,180,"256");
//	dc.TextOut(45+4+128,180,"128");
	if (flagHis)
	{
//=========归一化便于显示==============
	for (int k=0;k<256;k++)
	{
		if (gray[k]>max)
			max=gray[k];
	}
	for (k=0;k<256;k++)
		gray[k]=gray[k]*150/max;
		for (int i=0;i<256;i++)
		{
			dc.MoveTo(i+46,174);
			dc.LineTo(i+46,174-gray[i]);
		}
	}		
	if(threshold!=0)
	{
		CPen newPen(PS_DOT,1,(COLORREF)0);
		CPen* pOldPen=dc.SelectObject(&newPen);	
		dc.SelectObject(GetStockObject(HOLLOW_BRUSH));
		dc.MoveTo(46+threshold,190);
		dc.LineTo(46+threshold,16);	
		char buffer[10];
		_itoa( threshold, buffer, 10 );
		dc.TextOut(46+threshold+4,180,buffer);
		dc.SelectObject(pOldPen);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -