To open a picture:
voidCimageprodlg::onimageopen () {//TODO: Add Command handler code hereInvalidate (); CFileDialog dlg (TRUE, NULL, NULL, Ofn_filemustexist| Ofn_pathmustexist |ofn_readonly, TEXT ("supported Types (*.jpg;*.png;*.gif;*.bmp; ...) | *.jpg;*.png;*.gif;*.bmp| Tiff (*.tiff;*.tif) |*.tiff;*.tif| All Files (*. *) |*.*| |"), NULL); Dlg.m_ofn.nFilterIndex=1; Dlg.m_ofn.hwndOwner=m_hwnd; Dlg.m_ofn.lStructSize=sizeof(OPENFILENAME); Dlg.m_ofn.lpstrTitle= TEXT ("Opening image...\0"); Dlg.m_ofn.nMaxFile=MAX_PATH; if(DLG. DoModal () = =IDOK) {M_path=dlg. GetPathName (); M_capacity=TRUE; UpdateData (FALSE); } Else return; //left picture control display picture//string S_path (M_path. GetBuffer ()); //This will include <string.h> Char*S_path; S_path= M_path. GetBuffer (M_path. GetLength ());//convert CString to char * format//m_staticpath.setwindowtexta (M_path); //display a picture path to a static text controlMat mat_image = Imread (S_path,1); Savedimage= Mat_image;//Global VariablesIplimage image =Mat_image; DRAWPICTOHDC (&image, Id_showleft);}
Save Picture:
(You need to enter the full path, including the extension name)
voidCimageprodlg::onsaveas () {//TODO: Add Command handler code here if(m_capacity) {CFileDialog dlg (FALSE, NULL, NULL, Ofn_filemustexist| Ofn_pathmustexist |ofn_readonly, TEXT ("supported Types (*.jpg;*.png;*.gif;*.bmp; ...) | *.jpg;*.png;*.gif;*.bmp| Tiff (*.tiff;*.tif) |*.tiff;*.tif| All Files (*. *) |*.*| |"), NULL); Dlg.m_ofn.nFilterIndex=1; Dlg.m_ofn.hwndOwner=m_hwnd; Dlg.m_ofn.lStructSize=sizeof(OPENFILENAME); Dlg.m_ofn.lpstrTitle= TEXT ("Saving Image ... [Meantime input extension name!] /"); Dlg.m_ofn.nMaxFile=MAX_PATH; CString strpath (""), Strext (""); Charwrite[10000]; if(DLG. DoModal () = =IDOK) {strpath= Dlg. GetPathName ();//file name Char*S_path; S_path=Strpath.getbuffer (Strpath.getlength ()); Imwrite (S_path, savedimage); Strpath.releasebuffer (); } } ElseMessageBox ("The original picture has not been selected and the picture cannot be saved! ");}
#OpenCV # #MFC # Open and save pictures with MFC and OpenCV through the System dialog box