Currently I have this:
printscreen.Save(myOutputLocation + myImageName + myImageExtension, ImageFormat.Png);
However, I would like to specify the ImageFormat class property with a string, but I can't get it to work:
string myString = textBox1.Text;
printscreen.Save(myOutputLocation + myImageName + myImageExtension, ImageFormat.myString);
I would write a method ParseImageFormat using reflection, and use it as
printscreen.Save(myOutputLocation + myImageName + myImageExtension,
ParseImageFormat(myString));
where myString should be one of MemoryBmp,Bmp,Emf,Wmf,Gif,Jpeg,Png,Tiff,Exif,Icon
public static ImageFormat ParseImageFormat(string str)
{
return (ImageFormat)typeof(ImageFormat)
.GetProperty(str, BindingFlags.Public | BindingFlags.Static | BindingFlags.IgnoreCase)
.GetValue(null);
}
You can use only any of defined formats of ImageFormat
:
Bmp, Emf, Exif, Gif, Guid, Icon, Jpeg, MemoryBmp, Png, Tiff, Wmf
If you want to set your own format then use
printscreen.Save(myOutputLocation + myImageName + myImageExtension);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With