//首先安装openCV1.0 //配置目录 //配置项目属性,LINK标签要加入cxcore.lib cv.lib ml.lib cvaux.lib highgui.lib cvcam.lib //简单显示一幅图的源码 #include "cv.h" #include "highgui.h" int main(int argc, char* argv[]) { IplImage* pImg; pImg = cvLoadImage("D://img//y8.jpg", 1); // 注意是双斜杠 cvNamedWindow("Image", 1); cvShowImage("Image", pImg); cvWaitKey(0); cvDestroyWindow("Image"); cvReleaseImage(&pImg); return 0; } //将image贴到ID所在区域的通用代码 void CCaptureImageDlg::DrawPicToHDC(IplImage* image, UINT ID) { /* CDC* pDC = GetDlgItem(ID)->GetDC(); HDC hDC = pDC->GetSafeHdc(); CRect rect; GetDlgItem(ID)->GetClientRect(&rect); CvvImage cimg; cimg.CopyOf(image); cimg.DrawToHDC(hDC,&rect); ReleaseDC(pDC); */ CDC* pDC = GetDlgItem(ID)->GetDC(); HDC hDC = pDC->GetSafeHdc(); CRect rect; GetDlgItem(ID)->GetClientRect(&rect); int rw = rect.right - rect.left; int rh = rect.bottom - rect.top; int iw = image->width; int ih = image->height; int tx = (rw - iw) / 2; int ty = (rh - ih) / 2; SetRect(rect, tx, ty, tx + iw, ty + ih); CvvImage cimg; cimg.CopyOf(image); cimg.DrawToHDC(hDC,&rect); ReleaseDC(pDC); }