www.pudn.com > dip.rar > GreyDlg.cpp


// GreyDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "dip.h" 
#include "GreyDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CGreyDlg dialog 
 
 
CGreyDlg::CGreyDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CGreyDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CGreyDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	int i; 
	for(i=0;i<256;i++) 
		grey[i]=0; 
} 
 
 
void CGreyDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CGreyDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CGreyDlg, CDialog) 
	//{{AFX_MSG_MAP(CGreyDlg) 
	ON_WM_PAINT() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CGreyDlg message handlers 
 
int CGreyDlg::DoModal()  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	 
	return CDialog::DoModal(); 
} 
 
 
void CGreyDlg::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	// TODO: Add your message handler code here 
	//显示背景框 
	dc.Rectangle(10,10,300,400); 
	int i; 
	LONG greymax=0; 
	for(i=0;i<256;i++) 
	{ 
		if (grey[i]>greymax) greymax=grey[i]; 
	} 
	 
	//显示灰度直方图 
	 
	dc.MoveTo(283,395-int(grey[0]*1.0/greymax*380));	 
	for(i=1;i<256;i++) 
	{ 
		dc.LineTo(283-i,395-int(grey[i]*1.0/greymax*380)); 
		dc.MoveTo(283-i,395-int(grey[i]*1.0/greymax*380)); 
	} 
 
	// Do not call CDialog::OnPaint() for painting messages 
}