Skip to content

Instantly share code, notes, and snippets.

@edwardtoday
Last active August 29, 2015 14:04
Show Gist options
  • Save edwardtoday/33584402d217395e54c9 to your computer and use it in GitHub Desktop.
Save edwardtoday/33584402d217395e54c9 to your computer and use it in GitHub Desktop.
MFC button handler to open and show an image.
// Open image
CString FilePathName;
CFileDialog dlg(TRUE);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
if (dlg.DoModal() == IDOK) {
FilePathName = dlg.GetPathName();
GetDlgItem(IMAGE_FILENAME)->SetWindowText(FilePathName);
CT2CA pszConvertedAnsiString(FilePathName);
cv::Mat img = cv::imread(std::string(pszConvertedAnsiString),
CV_LOAD_IMAGE_UNCHANGED);
//if (!img.empty()) {
// cv::namedWindow("Preview",
// CV_WINDOW_AUTOSIZE); //create a window with the name "Preview"
// cv::imshow("Preview",
// img); //display the image which is stored in the 'img' in the "Preview" window
// cv::waitKey(0); //wait infinite time for a keypress
// cv::destroyWindow("Preview"); //destroy the window with the name, "Preview"
//}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment