1
A
回答
2
这里是一个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)
{
...
}
非常感谢你,我现在知道如何在C++中做到这一点。 – user25749 2009-06-10 02:56:13