Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET image.Save, what format is the file saved in?

Tags:

.net

image

When I use, e.g. in C# the image class which implements the Save method, what format will the file be? I assume it will be what I enter to save dialog but what if I enter some nonsense extension?

like image 926
Mocco Avatar asked Jan 21 '23 12:01

Mocco


2 Answers

EDIT: BMP is the default format.

Seems that PNG is the default format. The Save() method does provide overrides to specify different formats.

 Image.Save("c:\\myimage.gif", System.Drawing.Imaging.ImageFormat.Gif);

The file extension has no bearing on the actual image format used.

http://msdn.microsoft.com/en-us/library/ktx83wah.aspx

like image 196
Craigt Avatar answered Jan 28 '23 17:01

Craigt


If you don't specify format the image will be saved to the format returned by Image.RawFormat Property. This means that it does not matter what you enter in the filename. The RawFormat property returns the format returned by native GdipGetImageRawFormat function which should correspond to the current format of the image.

like image 41
Giorgi Avatar answered Jan 28 '23 16:01

Giorgi