某些 jpeg 图像以 .bmp 扩展名存储。 我想使用gdi+来获取图像文件的真实类型,我该怎么做?
非常感谢!
最佳答案
这是一个 C# 版本(使用 System.Drawing.Imaging 命名空间):
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;
}
使用此功能,您可以执行以下操作:
ImageFormat fmt = getImageFileFormat( @"some file" );
if ( fmt.Guid == ImageFormat.Jpeg.Guid )
{
...
}
else if ( fmt.Guid == ImageFormat.Bmp.Guid )
{
...
}
关于image - 如何在 C++ 中使用 GDI+ 获取图像文件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/968842/