Ask Your Question
1

Save Image with saveFileDialog

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

Schinkenbrot gravatar image

updated 2017-09-26 09:18:18 -0600

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";
             saveFileDialog1->ShowDialog(); 

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

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

             }

Any suggestions?
Thanks!

edit retag flag offensive close merge delete

Comments

1

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 -0600 )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 -0600 )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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

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

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

Question Tools

1 follower

Stats

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

Seen: 1,497 times

Last updated: Feb 24 '16