#OpenCV # #MFC # Open and save pictures with MFC and OpenCV through the System dialog box

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.