Some jpeg image is stored with .bmp ext. I want to use gdi+ to get the real type of the image file, how can I do this?
Many thanks!
Some jpeg image is stored with .bmp ext. I want to use gdi+ to get the real type of the image file, how can I do this?
Many thanks!
Here is a C# version (using the System.Drawing.Imaging namespace):
public static ImageFormat getImageFileFormat( string filename )
{
using ( var fs = new System.IO.FileStream( filename, System.IO.FileMode.Open ) )
using ( var img = Image.FromStream( fs, true, false ) )
return img.RawFormat;
}
With this function, you can do something like:
ImageFormat fmt = getImageFileFormat( @"some file" );
if ( fmt.Guid == ImageFormat.Jpeg.Guid )
{
...
}
else if ( fmt.Guid == ImageFormat.Bmp.Guid )
{
...
}