I would like to be able to save image according to extension that is entered in the save file dialog. I have found out that simply entering e.g. “JPG” does not cause the Save method to use this format of course.
Parsing the extension and then using e.g. switch and setting correct format sounds a bit ackward to me. Or there is no better way?
I would like to be able to save image according to extension that is
Share
you can get the file name specified in the
SaveDialog.FileNamethen withPath.GetExtension()or similar you can get the string which will be used as extension.What you will do after depends on your specific application design, if you are saving a text file you can also call it image1.png, but it will still be a text file.
if you have an image object in memory and want to save in the proper format depending on the selected extension, I would use a switch/case and use the proper overload or parameter values of the Image.Save to handle the different image formats.
Example