www.pudn.com > moisac_face_detect.rar > FaceDecView.cpp
// FaceDecView.cpp : implementation of the CFaceDecView class
//
#include "stdafx.h"
#include "FaceDec.h"
#include "FaceDecDoc.h"
#include "FaceDecView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFaceDecView
IMPLEMENT_DYNCREATE(CFaceDecView, CView)
BEGIN_MESSAGE_MAP(CFaceDecView, CView)
//{{AFX_MSG_MAP(CFaceDecView)
ON_COMMAND(ID_BUTTONGRAY, OnButtongray)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_BUTTONDETECT, OnButtondetect)
ON_COMMAND(ID_BUTTONMOSAIC, OnButtonmosaic)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFaceDecView construction/destruction
CFaceDecView::CFaceDecView()
{
// TODO: add construction code here
myP=NULL;
}
CFaceDecView::~CFaceDecView()
{
if(myP!=NULL) delete myP;
}
BOOL CFaceDecView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFaceDecView drawing
void CFaceDecView::OnDraw(CDC* pDC)
{
CFaceDecDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(myP!=NULL)
{
DrawCenterDC(pDC); //why?
}
}
/////////////////////////////////////////////////////////////////////////////
// CFaceDecView diagnostics
#ifdef _DEBUG
void CFaceDecView::AssertValid() const
{
CView::AssertValid();
}
void CFaceDecView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFaceDecDoc* CFaceDecView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFaceDecDoc)));
return (CFaceDecDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFaceDecView message handlers
void CFaceDecView::OnButtongray()
{
BYTE R,G,B;
for(int i=0; i<(int)myP->myPHeight; i++)
{
for(int j=0; j<(int)myP->myPWidth; j++)
{
R=(BYTE)myP->myHSIArray[i*(myP->myPWidth)+j].I;
G=R;
B=R;
myP->myPArray[i*(myP->myPWidth)+j]=RGB(R,G,B);
myP->myHSIArray[i*(myP->myPWidth)+j].S=0;
myP->myHSIArray[i*(myP->myPWidth)+j].H=0;
}
}
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CFaceDecView::OnFileOpen()
{
// TODO: Add your command handler code here
CString fName;
CFileDialog fDlg(true);
fDlg.DoModal();
fName=fDlg.GetFileName();
if(fName==CString("")) return;
myP=new ImagePr;
myP->ReadDIB(fName);
myP->HSItrans('t');
//draw it
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CFaceDecView::OnPaint()
{
CPaintDC dc(this); // device context for painting
if(myP!=NULL)
{
//DrawCenterDC(&dc); //why?
//ReleaseDC(&dc);
}
}
void CFaceDecView::DrawCenterDC(CDC *pDC)
{
int i,j;
CRect tRect;
CPoint tCPoint;
GetClientRect(&tRect);
//SendMessage(WM_PAINT);---- Cannot refresh!
pDC->FillSolidRect(tRect,RGB(0,0,0));//255,255,255Set background and refresh
tCPoint=tRect.CenterPoint();
tCPoint-=CSize(myP->myPWidth/2,myP->myPHeight/2);
for(i=0; i<(int)myP->myPHeight; i++)
for(j=0; j<(int)myP->myPWidth; j++)
pDC->SetPixel(j+tCPoint.x , i+tCPoint.y , myP->myPArray[i*(myP->myPWidth)+j]);
}
void CFaceDecView::OnButtondetect()
{
// TODO: Add your command handler code here
myP->FaceDection();
}
void CFaceDecView::OnButtonmosaic()
{
// TODO: Add your command handler code here
myP->TestMosaic();
//draw it
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}