2009-06-09 29 views

回答

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) 
    { 
     ... 
    } 
+0

非常感謝你,我現在知道如何在C++中做到這一點。 – user25749 2009-06-10 02:56:13

相關問題