1.图片适应PIC conrol大小
g_SrcImage = imread(fileDict[0]); //加载图片 CRect rect; m_pic.GetWindowRect(rect); //获取picture control控件变量的rect namedWindow(WINDOW_NAME,CV_WINDOW_NORMAL);//可以改变窗口大小 resizeWindow(WINDOW_NAME, rect.Width(), rect.Height());//根据piccontrol的大下设置opencv窗口的大小 HWND hWnd = (HWND)cvGetWindowHandle(WINDOW_NAME);//嵌套opencv窗口 HWND hParent = ::GetParent(hWnd); ::SetParent(hWnd, GetDlgItem(IDC_PIC)->m_hWnd); ::ShowWindow(hParent, SW_HIDE);
imshow(WINDOW_NAME, g_SrcImage);//将图片显示在opencv窗口上,会强制改变图片原始比例
2.PIC Control大小适应图片
1 namedWindow(WINDOW_NAME);//创建OpenCV窗口 2 HWND hWnd = (HWND)cvGetWindowHandle(WINDOW_NAME);//嵌套opencv窗口 3 HWND hParent = ::GetParent(hWnd); 4 ::SetParent(hWnd, GetDlgItem(IDC_PIC)->m_hWnd); 5 ::ShowWindow(hParent, SW_HIDE); 6 7 8 g_SrcImage = imread(fileDict[0]); //加载图片 9 10 CWnd* pWnd1 = GetDlgItem(IDD_SEG_DIALOG); //获取主窗口句柄 11 12 int x = GetSystemMetrics(SM_CXSCREEN) / 2 - g_SrcImage.cols / 2; //使mfc窗口居中显示,获取对应于屏幕的左上角点 13 int y = GetSystemMetrics(SM_CYSCREEN) / 2 - g_SrcImage.rows / 2; 14 15 SetWindowPos(pWnd1, x, y, g_SrcImage.cols + 180, g_SrcImage.rows + 65, SWP_SHOWWINDOW); //根据图片大小,设置mfc窗口位置和大小 16 m_pic.MoveWindow(150, 10, g_SrcImage.cols, g_SrcImage.rows); //根据图片大小,设置piccontrol大小 17 18 imshow(WINDOW_NAME, g_SrcImage);//opencv显示图片 19 waitKey(20);