【问题标题】:How can I get the mime-type of an Image class instance in memory in c#?如何在 c# 的内存中获取 Image 类实例的 mime 类型?
【发布时间】:2012-11-15 12:07:01
【问题描述】:

在我为工作中的一些基础设施项目编写的库中,我有一种方法可以创建各种比例的图像(用于缩略图等......)。但是,由于各种原因,我存储这些数据的系统需要在数据库中声明一个 mime 类型。

有没有办法从传入的 c#Image 类中获取 Mime 类型,还是我必须让外部应用程序与图像一起传入 Mimetype?

【问题讨论】:

    标签: c# image mime-types


    【解决方案1】:

    你可以从Image获取ImageFormat,你可以从ImageCodecInfo获取MIME类型。您需要做的就是将两者联系在一起:

    ImageFormat format = yourImage.RawFormat;
    ImageCodecInfo codec = ImageCodecInfo.GetImageDecoders().First(c => c.FormatID == format.Guid);
    string mimeType = codec.MimeType;
    

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 2021-10-14
      • 2011-04-11
      • 2011-05-27
      • 1970-01-01
      • 2023-02-21
      • 2013-07-07
      • 2018-01-17
      相关资源
      最近更新 更多