【问题标题】:How to Get a image file type using GDI+ in c++?如何在 C++ 中使用 GDI+ 获取图像文件类型?
【发布时间】:2009-06-09 08:26:00
【问题描述】:

一些 jpeg 图像以 .bmp 扩展名存储。 我想用gdi+来获取图片文件的真实类型,怎么办?

非常感谢!

【问题讨论】:

    标签: image file gdi+ types


    【解决方案1】:

    这是一个 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++了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多