www.gusucode.com > 帧差法检测运动物体取背景程序 > 帧差法检测运动物体取背景程序/code/bmptestDlg.cpp

    // bmptestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "bmptest.h"
#include "bmptestDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
//Download by http://www.newxing.com
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBmptestDlg dialog

CBmptestDlg::CBmptestDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBmptestDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBmptestDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

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

BEGIN_MESSAGE_MAP(CBmptestDlg, CDialog)
	//{{AFX_MSG_MAP(CBmptestDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_S1, OnButtonS1)
	ON_BN_CLICKED(IDC_BUTTON_S2, OnButtonS2)
	ON_BN_CLICKED(IDC_WORK, OnWork)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_RESULT, OnButtonResult)
	ON_BN_CLICKED(IDC_MARK, OnMark)
	ON_BN_CLICKED(IDC_LIANTONG, OnLiantong)
	ON_BN_CLICKED(IDC_TRACK2, OnTrack2)
	ON_BN_CLICKED(IDC_CHUIZHIPZ, OnChuizhipz)
	ON_BN_CLICKED(IDC_SHUIPINGPZ, OnShuipingpz)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_CHUIZHIFS, OnChuizhifs)
	ON_BN_CLICKED(IDC_SHUIPINGFS, OnShuipingfs)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBmptestDlg message handlers

BOOL CBmptestDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	 lpBits1=NULL;
	 lpBits2=NULL;
	 pUnchResult=NULL;
	 p_temp=NULL;
	 lpBitmap=NULL;
	 lpBitmapRes=NULL;
	 s1flag=FALSE;
	 s2flag=FALSE;
	 resflag=FALSE;
	 bdflag=FALSE;
	 this->GetDlgItem(IDC_Threshold)->SetWindowText("35");
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CBmptestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}
BOOL CBmptestDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( pMsg->message   ==   WM_KEYDOWN   &&   pMsg->wParam   ==   VK_RETURN)//按下ESC   
	{   
		return   TRUE;   
	}   
	return CDialog::PreTranslateMessage(pMsg);
}


// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CBmptestDlg::OnPaint() 
{	
	CClientDC dc(this);	
    CRect rt;
	if(s1flag)
	{
		this->GetDlgItem(IDC_SOURCE1)->GetWindowRect(&rt);
		ScreenToClient(&rt);
		dc.DPtoLP(&rt);
		StretchDIBits(dc,rt.left,rt.top,rt.Size().cx,rt.Size().cy,
		0,0,m_width,m_height,lpBits1,lpBitmap,BI_RGB,SRCCOPY);
	}
	if(s2flag)
	{
		this->GetDlgItem(IDC_SOURCE2)->GetWindowRect(&rt);
		ScreenToClient(&rt);
		dc.DPtoLP(&rt);
		StretchDIBits(dc,rt.left,rt.top,rt.Size().cx,rt.Size().cy,
			0,0,m_width,m_height,lpBits2,lpBitmap,BI_RGB,SRCCOPY);

	}
	if(resflag)
	showresult(pUnchResult);
	if (bdflag)
	{
		CPen borderpen;
		CPen* poldpen;
		borderpen.CreatePen(PS_SOLID,1,RGB(255,0,0));
		poldpen=dc.SelectObject(&borderpen);
		for(UINT n=0;n<=x_sign;n++)
			if (flag[n]!=0)
		{
			   
				dc.MoveTo(CPoint(boder[n].left,boder[n].top));
				dc.LineTo(CPoint(boder[n].right,boder[n].top));
				dc.LineTo(CPoint(boder[n].right,boder[n].bottom));
				dc.LineTo(CPoint(boder[n].left,boder[n].bottom));
				dc.LineTo(CPoint(boder[n].left,boder[n].top));
				
				
			}
	dc.SelectObject(poldpen);
	}
	
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
	
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CBmptestDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CBmptestDlg::OnButtonS1() 
{
	// TODO: Add your control notification handler code here
	CString strfilter="Bitmap image|*.bmp|";	
	CFileDialog dlg(TRUE,
		NULL,
		NULL,
		OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST,
		strfilter
		);
	if(dlg.DoModal()!=IDOK)
	return;
	CString s1path=dlg.GetPathName( );
	this->GetDlgItem(IDC_SOURCE1_PATH)->SetWindowText(s1path);
    readtomemory(s1path,TRUE);
	CClientDC dc(this);	
    CRect rt;	
	this->GetDlgItem(IDC_SOURCE1)->GetWindowRect(&rt);
	ScreenToClient(&rt);
	dc.DPtoLP(&rt);
    StretchDIBits(dc,rt.left,rt.top,rt.Size().cx,rt.Size().cy,
		0,0,m_width,m_height,lpBits1,lpBitmap,BI_RGB,SRCCOPY);
	s1flag=TRUE;
	
}


void CBmptestDlg::OnButtonS2() 
{
	// TODO: Add your control notification handler code here
	CString strfilter="Bitmap image|*.bmp|";	
	CFileDialog dlg(TRUE,
		NULL,
		NULL,
		OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST,
		strfilter
		);
	if(dlg.DoModal()!=IDOK)
		return;
	CString s2path=dlg.GetPathName( );
	this->GetDlgItem(IDC_SOURCE2_PATH)->SetWindowText(s2path);
    readtomemory(s2path,FALSE);
	CClientDC dc(this);	
    CRect rt;	
	this->GetDlgItem(IDC_SOURCE2)->GetWindowRect(&rt);
	ScreenToClient(&rt);
	dc.DPtoLP(&rt);
    StretchDIBits(dc,rt.left,rt.top,rt.Size().cx,rt.Size().cy,
		0,0,m_width,m_height,lpBits2,lpBitmap,BI_RGB,SRCCOPY);
	s2flag=TRUE;
}
void CBmptestDlg::readtomemory(CString fpath,BOOL firstbmp)
{
	CFile file;
    file.Open(fpath,CFile::modeRead|CFile::shareDenyWrite);	
	file.Read(&bfhHeader,sizeof(BITMAPFILEHEADER));	
    uBmpInfoLen=(UINT)bfhHeader.bfOffBits-sizeof(BITMAPFILEHEADER);
	if (lpBitmap!=NULL)
	{ 
		delete[] lpBitmap;
		lpBitmap=NULL;
	}
	lpBitmap=(LPBITMAPINFO) new BYTE[uBmpInfoLen];
	file.Read((LPVOID) lpBitmap,uBmpInfoLen);	
	dwBitlen=bfhHeader.bfSize - bfhHeader.bfOffBits;
	m_width=((LPBITMAPINFOHEADER)lpBitmap)->biWidth;
    m_height=((LPBITMAPINFOHEADER)lpBitmap)->biHeight;
	wwidthbytes24=(m_width*24+31)/32* 4 ;
	wwidthbytes8=(m_width*8+31)/32* 4 ;
	m_resultbits=wwidthbytes8*m_height;
    if(firstbmp)
	{	
		if (lpBits1!=NULL)
		{ 
			delete[] lpBits1;
			lpBits1=NULL;
		}
	lpBits1=new BYTE[dwBitlen];
	}
	else
	{	
		if (lpBits2!=NULL)
		{ 
			delete[] lpBits2;
			lpBits2=NULL;
		}
	lpBits2=new BYTE[dwBitlen];
	}
		
	if(firstbmp)
	{	
		file.ReadHuge(lpBits1,dwBitlen);
		file.Close();
	}
	else
	{	
		file.ReadHuge(lpBits2,dwBitlen);
		file.Close();
	}
}


void CBmptestDlg::OnWork() 
{
	// TODO: Add your control notification handler code here
	CString   Threshold;
	this->GetDlgItem(IDC_Threshold)->GetWindowText(Threshold);
    nThreshold=atoi(Threshold.GetBuffer(0));
	
	if (pUnchResult!=NULL)
	{ 
		delete[] pUnchResult;
		pUnchResult=NULL;
	}
	pUnchResult=new BYTE[m_resultbits];
	memset((LPVOID)pUnchResult,0,m_resultbits);
	BinaFrameDiff((BYTE *)lpBits1,(BYTE *)lpBits2);
	showresult(pUnchResult);

}
void CBmptestDlg::BinaFrameDiff(BYTE *pUnchImg1,BYTE *pUnchImg2)
{
	UINT i,j;
	for (UINT y=0;y<m_height;y++) 
		for (UINT x=0;x<m_width;x++)
		{
			i=x*3+y*wwidthbytes24;
			j=x+y*wwidthbytes8;
			if(abs(pUnchImg1[i] - pUnchImg2[i]) > nThreshold || abs(pUnchImg1[i+1] - pUnchImg2[i+1]) > nThreshold ||abs(pUnchImg1[i+2] - pUnchImg2[i+2]) > nThreshold)
				pUnchResult[j]=0;
			else
				pUnchResult[j]=255;		
		}
		
}

void CBmptestDlg::showresult(BYTE* pbmp)
{
	CClientDC dc(this);	
    CRect rt;	
	this->GetDlgItem(IDC_RESULT)->GetWindowRect(&rt);
	ScreenToClient(&rt);
	dc.DPtoLP(&rt);
    if (lpBitmapRes==NULL)
	{
		uResInfoLen=sizeof(BITMAPINFOHEADER)+256*4;
		lpBitmapRes=(LPBITMAPINFO)new BYTE[uResInfoLen];
		memset((LPVOID)lpBitmapRes,0,uResInfoLen);
		if (lpBitmap!=NULL)
			memcpy((LPVOID)lpBitmapRes,(LPVOID)lpBitmap,uBmpInfoLen);	
		lpBitmapRes->bmiHeader.biBitCount=8;
		lpBitmapRes->bmiHeader.biSizeImage=m_resultbits;
		for(UINT i=0;i<256;i++)
		{
			lpBitmapRes->bmiColors[i].rgbBlue=i;
			lpBitmapRes->bmiColors[i].rgbRed=i;
		lpBitmapRes->bmiColors[i].rgbGreen=i;

		}
		
	}
	StretchDIBits(dc,rt.left,rt.top,rt.Size().cx,rt.Size().cy,0,0,m_width,m_height,pbmp,lpBitmapRes,BI_RGB,SRCCOPY);
   resflag=TRUE;
}



void CBmptestDlg::OnButtonResult() 
{  
  CString strfilter="Bitmap image|*.bmp||";	
  CFileDialog dlg(false,
	  "bmp",
	  NULL,
	  NULL,
	  strfilter
	  );
  if(dlg.DoModal()!=IDOK)
	  return;
  m_resultpath=dlg.GetPathName( );
  this->GetDlgItem(IDC_RESULT_PATH3)->SetWindowText(m_resultpath);
  writetofile();
 
}

void CBmptestDlg::writetofile() 
{
	CFile file;	
	file.Open(m_resultpath,CFile::modeWrite|CFile::modeCreate);
	bfhHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+uResInfoLen;
    bfhHeader.bfSize=bfhHeader.bfOffBits+m_resultbits;    
	file.Write(&bfhHeader,sizeof(BITMAPFILEHEADER));
	file.Write((LPVOID) lpBitmapRes,uResInfoLen);
	file.Write((LPVOID) pUnchResult,m_resultbits);	
	file.Close();
}



void CBmptestDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnClose();
	if(lpBits1!=NULL)
		delete[] lpBits1;
	if(lpBits2!=NULL)
		delete[] lpBits2;
	if(lpBitmap!=NULL)
		delete[] lpBitmap;
	if(lpBitmapRes!=NULL)
		delete[] lpBitmapRes;
	if(pUnchResult!=NULL)
		delete[] pUnchResult;  
	if(p_temp!=NULL)
		delete[] p_temp; 
	
}

void CBmptestDlg::OnMark() 
{
	// TODO: Add your control notification handler code here
	
	UINT m_temp=0;
	UINT x_temp=0;
	UINT y_temp=0;	
	UINT stop=0,height,wide;
	BYTE* p_data=pUnchResult;
	x_sign=0;
	for(UINT i=0;i<255;i++)
		flag[i]=0;
	height=m_height;
    wide=m_width;
	if (p_temp!=NULL)
	{ 
		delete[] p_temp;
		p_temp=NULL;
	}
	p_temp=new BYTE[wide*height];
		memset(p_temp,255,wide*height);
		//从左到右标号
		for(UINT j=1;j<m_height-1;j++)	// 每行
		{
			for(UINT i=1;i<m_width-1;i++)	// 每列
			{
				if(*(p_data+(height-j-1)*wide+i)==0)//若当前点为黑点
				{
					if(*(p_data+(height-j-1+1)*wide+i+1)==0)//右上
					{
						*(p_temp+(height-j-1)*wide+i)=*(p_temp+(height-j-1+1)*wide+i+1);
						x_temp=*(p_temp+(height-j-1+1)*wide+i+1);
						flag[x_temp]+=1;
						if(*(p_data+(height-j-1)*wide+i-1)==0&&*(p_temp+(height-j-1)*wide+i-1)!=x_temp)//左前
						{
							y_temp=*(p_temp+(height-j-1)*wide+i-1);
							for(UINT m=1;m<=height-1;m++)
								for(UINT n=1;n<=wide-1;n++)
								{
									if(*(p_temp+(height-m-1)*wide+n)==y_temp)
									{	
										flag[y_temp]=0;
										*(p_temp+(height-m-1)*wide+n)=x_temp;
										flag[x_temp]+=1;
									}
								}
						}//end//左前
						if(*(p_data+(height-j-1+1)*wide+i-1)==0&&*(p_temp+(height-j-1+1)*wide+i-1)!=x_temp)//左上
						{
							y_temp=*(p_temp+(height-j-1+1)*wide+i-1);
							for(UINT m=1;m<=height-1;m++)
								for(UINT n=1;n<=wide-1;n++)
								{
									if(*(p_temp+(height-m-1)*wide+n)==y_temp)
									{	
										flag[y_temp]=0;
										*(p_temp+(height-m-1)*wide+n)=x_temp;
										flag[x_temp]+=1;
									}
								}
						}//end//左上
					}
					else if(*(p_data+(height-j-1+1)*wide+i)==0)//正上
					{
						*(p_temp+(height-j-1)*wide+i)=*(p_temp+(height-j-1+1)*wide+i);
						x_temp=*(p_temp+(height-j-1+1)*wide+i);
						flag[x_temp]+=1;
					}
					else if(*(p_data+(height-j-1+1)*wide+i-1)==0)//左上
					{
						*(p_temp+(height-j-1)*wide+i)=*(p_temp+(height-j-1+1)*wide+i-1);
						x_temp=*(p_temp+(height-j-1+1)*wide+i-1);
						flag[x_temp]+=1;
					}
					else if(*(p_data+(height-j-1)*wide+i-1)==0)//左前
					{
						*(p_temp+(height-j-1)*wide+i)=*(p_temp+(height-j-1)*wide+i-1);
						x_temp=*(p_temp+(height-j-1)*wide+i-1);
						flag[x_temp]+=1;
					}
					else//没有
					{				
						++x_sign;
						m_temp=x_sign;
						*(p_temp+(height-j-1)*wide+i)=m_temp;
						flag[m_temp]=1;
						
					}
				}//end if
			}// 每列
		}//end 每行
	memcpy(pUnchResult, p_temp, wide *height);
	showresult(pUnchResult);
}

void CBmptestDlg::OnLiantong() 
{
	// TODO: Add your control notification handler code here
	BYTE fg[255]={0};
	memset(fg,0,255);
	UINT y_sign=0;
	UINT m_Area=0;//定义一个面积
	for(UINT i=0;i<=x_sign;i++)
	{
		if(flag[i]!=0)
		{
			{
				fg[y_sign]=flag[i];
				++y_sign;
			}			
		}
		m_Area+=flag[i];
	}
	CString strout;
	strout.Format("%d ",y_sign);
	this->GetDlgItem(IDC_EDIT1)->SetWindowText(strout);
	strout.Format("%d ",m_Area);
	this->GetDlgItem(IDC_EDIT2)->SetWindowText(strout);
	UINT sum=0;
    strout="";
	for(i=0;i<x_sign;i++)
	if(flag[i]!=0)
	{
		sum++;
		CString str1;
		str1.Format("物体%3d    该区面积:%d\r\n",sum,flag[i]);
		strout=strout+str1;
		this->GetDlgItem(IDC_EDIT3)->SetWindowText(strout);
	}
	
}

void CBmptestDlg::OnTrack2() 
{
	// TODO: Add your control notification handler code here
	UINT xmin[255],xmax[255],ymin[255],ymax[255],i;
	for(i=0;i<255;i++)
	{
		xmin[i]=320;	
		xmax[i]=0;	
		ymin[i]=240;	
		ymax[i]=0;
	
	}
	for(UINT y=0;y<m_height;y++)	
	{
		for(UINT x=0;x<m_width;x++)	
		{
			for(UINT n=0;n<=x_sign;n++)
				if(flag[n]!=0) 
				if(*(p_temp+y*m_width+x)==n)
				{
					if(x<xmin[n]) xmin[n]=x;  
					if(x>xmax[n]) xmax[n]=x;
					if(y<ymin[n]) ymin[n]=y;
			        if(y>ymax[n]) ymax[n]=y;
				}
				
				
		}
	}
	
	CWnd* pwnd=this->GetDlgItem(IDC_SOURCE2);
	CRect rt;
	pwnd->GetWindowRect(&rt);
		ScreenToClient(&rt);
CClientDC dc(this);
CPen borderpen;
CPen* poldpen;
borderpen.CreatePen(PS_SOLID,1,RGB(255,0,0));
		poldpen=dc.SelectObject(&borderpen);
    for(UINT n=0;n<=x_sign;n++)
	if(flag[n]!=0) 
	{
		boder[n].left=xmin[n];    
		boder[n].top=m_height-ymax[n];
		boder[n].right=xmax[n];
		boder[n].bottom=m_height-ymin[n];
		
		boder[n].left=boder[n].left+rt.left;
		boder[n].top=boder[n].top+rt.top;
		boder[n].right=boder[n].right+rt.left;
		boder[n].bottom=boder[n].bottom+rt.top;  
		dc.DPtoLP(&boder[n]);
		
		bdflag=TRUE;
        
	}
	dc.SelectObject(poldpen);
	OnPaint();
	
}

void CBmptestDlg::OnChuizhipz() 
{
	// TODO: Add your control notification handler code here
	UINT height,wide;	
	height=m_height;
    wide=m_width;
	LPBYTE lpSrc,lpDst;
	if (p_temp!=NULL)
	{ 
		delete[] p_temp;
		p_temp=NULL;
	}
	p_temp=new BYTE[wide*height];
	memset(p_temp, (BYTE)255, wide * height);
	
	for(UINT j = 1; j < height - 1; j++)
	{
		for(UINT i = 0; i < wide; i ++)
		{
			lpSrc = (unsigned char *)(pUnchResult+ wide * j + i);
			lpDst = (unsigned char *)(p_temp + wide * j + i);
			*lpDst = 255;			 
			
			for (UINT n = 0; n < 3; n++)
			{
				if (*(lpSrc + (n - 1) * wide) <255)
				{
					*lpDst = *(lpSrc + (n - 1) * wide);
					break;
				}
			}				
		}
	}
	memcpy(pUnchResult, p_temp, wide *height);
	
	showresult(pUnchResult);
}

void CBmptestDlg::OnShuipingpz() 
{
	// TODO: Add your control notification handler code here
	UINT height,wide;	
	height=m_height;
    wide=m_width;
	LPBYTE lpSrc,lpDst;
    if (p_temp!=NULL)
	{ 
		delete[] p_temp;
		p_temp=NULL;
	}
	p_temp=new BYTE[wide*height];
    memset(p_temp, (BYTE)255, wide * height);
	for(UINT j = 1; j < height - 1; j++)
	{
		for(UINT i = 0; i < wide; i ++)
		{
					
			lpSrc = (unsigned char *)(pUnchResult+ wide * j + i);
			lpDst = (unsigned char *)(p_temp + wide * j + i);
			*lpDst = 255;			 
			for (UINT n = 0; n < 3; n++)
			{
				if (*(lpSrc + (n - 1) ) <255)
				{
					*lpDst = *(lpSrc + (n - 1) );
					break;
				}
			}				
		}
	}
	memcpy(pUnchResult, p_temp, wide *height);
	showresult(pUnchResult);
}
void CBmptestDlg::OnChuizhifs() 
{
	// TODO: Add your control notification handler code here
	UINT height,wide;	
	height=m_height;
    wide=m_width;
	LPBYTE lpSrc,lpDst;
	if (p_temp!=NULL)
	{ 
		delete[] p_temp;
		p_temp=NULL;
	}
	p_temp=new BYTE[wide*height];
	memset(p_temp, (BYTE)255, wide * height);
	
	for(UINT j = 1; j < height - 1; j++)
	{
		for(UINT i = 0; i < wide; i ++)
		{
			lpSrc = (unsigned char *)(pUnchResult+ wide * j + i);
			lpDst = (unsigned char *)(p_temp + wide * j + i);
			*lpDst = *lpSrc;			 
			for (UINT n = 0; n < 3; n++)
			{
				if (*(lpSrc + (n - 1) * wide) == 255)
				{
					*lpDst = 255;
					break;
				}
			}				
		}
	}

	memcpy(pUnchResult, p_temp, wide *height);
	
	showresult(pUnchResult);
}
void CBmptestDlg::OnShuipingfs() 
{
	// TODO: Add your control notification handler code here
	UINT height,wide;	
	height=m_height;
    wide=m_width;
	LPBYTE lpSrc,lpDst;
    if (p_temp!=NULL)
	{ 
		delete[] p_temp;
		p_temp=NULL;
	}
	p_temp=new BYTE[wide*height];
	memset(p_temp, (BYTE)255, wide * height);
	
	for(UINT j = 1; j < height - 1; j++)
	{
		for(UINT i = 0; i < wide; i ++)
		{
			lpSrc = (unsigned char *)(pUnchResult+ wide * j + i);
			lpDst = (unsigned char *)(p_temp + wide * j + i);
			*lpDst = *lpSrc;			 
			for (UINT n = 0; n < 3; n++)
			{
				if (*(lpSrc + (n - 1) ) == 255)
				{
					*lpDst = 255;
					break;
				}
			}				
		}
	}

	memcpy(pUnchResult, p_temp, wide *height);
	
	showresult(pUnchResult);
}
void CBmptestDlg::OnDelete() 
{
	// TODO: Add your control notification handler code here
	CString strsarea;
	UINT sarea;
	this->GetDlgItem(IDC_AREA)->GetWindowText(strsarea);
	sarea=atoi(strsarea.GetBuffer(0));
		for(UINT i=1;i<=x_sign;i++)
		{
			if(flag[i]<sarea)//判断连通区的面积(像素个数)是否消除
			{
				flag[i]=0;
				for(UINT m=1;m<m_height-1;m++)
					for(UINT n=1;n<m_width -1;n++)
					{
						if(*(p_temp+(m_height-m-1)*m_width+n)==i)
							*(p_temp+(m_height-m-1)*m_width+n)=255;
					}		
			}
		}
	memcpy(pUnchResult, p_temp, m_width *m_height);
	showresult(pUnchResult);
		
}