需要在工程中包含 文件 CvvImage.h 和 CvvImage.cpp。下载地址:http://download.csdn.net/detail/connor_lele/4687210
主要代码如下:
#include "CvvImage.h"
void CCorrectionDlg::OnBnClickedBtOpen()
{
// TODO: Add your control notification handler code here
CFileDialog IFileDlg(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_READONLY,
TEXT("支持的图像文件(*.jpg;*.gif;*.bmp;...)|*.jpg;*.gif;*.bmp|专用Tiff图像文件(*.tiff;*.tif)|*.tiff;*.tif|所有文件(*.*)|*.*||"),NULL);
IFileDlg.m_ofn.nFilterIndex=1;
IFileDlg.m_ofn.hwndOwner=m_hWnd;
IFileDlg.m_ofn.lStructSize=sizeof(OPENFILENAME);
IFileDlg.m_ofn.lpstrTitle=TEXT("打开图像文件...\0");
IFileDlg.m_ofn.nMaxFile=MAX_PATH;
if(IFileDlg.DoModal() == IDOK)
{
image_path = IFileDlg.GetPathName();
UpdateData(FALSE);
}
//CString 转 std::string
std::string temp(image_path.GetBuffer());
image_path.ReleaseBuffer(-1);
image_original = cv::imread(temp,1);
IplImage iplimg = image_original;
DrawPicToHDC(&iplimg, IDC_ST_ORIGINAL);
}
void CCorrectionDlg::DrawPicToHDC(IplImage *img, UINT ID)
{
CDC *pDC = GetDlgItem(ID)->GetDC();
HDC hDC= pDC->GetSafeHdc();
CRect rect;
GetDlgItem(ID)->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf(img);
cimg.DrawToHDC(hDC,&rect);
ReleaseDC(pDC);
}