Attention! This forum will be made read-only by Dec-20. Please migrate to Most of existing active users should've received invitation by e-mail.
Ask Your Question

Save Image with saveFileDialog

asked 2016-02-24 05:56:13 -0500

Schinkenbrot gravatar image

updated 2017-09-26 09:18:18 -0500

Hi! I am new to OpenCv and C++.

I word with Visual Studio 2013 and I want save an image with the saveFileDialog or with folderBrowserDialog from windows forms? Is that even possible?

I tried this but I get an error at the line "cv::imwrite(name, image); " : no suitable constructor exists to convert from "System::String^ to cv::String"

 saveFileDialog1->Filter = "JPEG Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
             saveFileDialog1->Title = "Save Image";

             if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK){

                String^ name = saveFileDialog1->FileName;
                  cv::imwrite(name, image);
                 MessageBox::Show("Successfully saved");


Any suggestions?

edit retag flag offensive close merge delete



do you have to use managed code ? you could use a simpl imshow(), and press crtl-s on that window.

( calls internal showSaveDialog(CvWindow* window) function)

berak gravatar imageberak ( 2016-02-24 06:01:31 -0500 )edit

Yes. I have to create a nice GUI where I can capture images from a webcam, do some transformations, face recognition and then save the new image in any directory... Is it even possible to convert System::String to cv::String?

Schinkenbrot gravatar imageSchinkenbrot ( 2016-02-24 06:17:03 -0500 )edit

Oh my God. It works with the conversion... Thanks thanks thanks! You saved my day :D I will keep your warning in my mind ;)

Schinkenbrot gravatar imageSchinkenbrot ( 2016-02-24 07:44:59 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-24 06:32:47 -0500

berak gravatar image

yea, you can:

System::String^ temp = saveFileDialog1->FileName;
IntPtr pointer_temp = Marshal::StringToHGlobalAnsi(temp);
const char* input_location = static_cast<const char*>(pointer_temp.ToPointer());

but take my warning: opencv and cli/managed stuff is not a marriage made in heaven

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-02-24 05:56:13 -0500

Seen: 743 times

Last updated: Feb 24 '16