image - 如何在 C++ 中使用 GDI+ 获取图像文件类型?

标签 image file gdi+ types

某些 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/

相关文章:

python - 如何在 python 中裁剪图像的底部(带字幕的部分)

java - 相机图像处理

java - Android 文件 IO : I and O Accessing Different Files

c++ - gdiplus 从字符串构造图像

c# - 即使位图设置为 Graphics.Clear(Color.Transparent),为什么调整大小时图像周围会出现黑色背景

c - 从图像中提取较小的图像

c++ - 如何使用 C++ 中的 Write 系统调用?

c - 如何确定缓冲区的大小

c# - 计算一条线的精确像素

android - 非库存相机的相机应用拍摄照片时未保存图像