void CDemo1View::Onbin()
{
CDemo1Doc *pDoc=GetDocument();
ImageDib *pDib=pDoc->GetPDib();
//异常判断
if(pDib->m_nBitCount!=24&&pDib->m_nBitCount!=8){
::MessageBox(0,"只处理彩色和灰度图像",MB_OK,0);
return ;
}
//将pDib中的图像数据作为输入数据,调用带参数的构造函数,
//定义GrayTrans类的对象graytrans
int thd=250;
GrayTrans graytrans(pDib->GetDimensions(),pDib->m_nBitCount,
pDib->m_lpColorTable, pDib->m_pImgData);
//调用Binary()对图像进行二值化,缺省状态下阈值为
graytrans.BinaryImage(thd);
//建立一个新视图,显示分割结果
CMainFrame* pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd);
pFrame->SendMessage(WM_COMMAND, ID_FILE_NEW);
CDemo1View* pView=(CDemo1View*)pFrame->MDIGetActive()->GetActiveView();
CDemo1Doc* pDocNew=pView->GetDocument();
ImageDib *dibNew=pDocNew->GetPDib();
dibNew->ReplaceDib(graytrans.GetDimensions(),graytrans.m_nBitCo