简体   繁体   English

如何在c#中获取内存中的mime类型的Image类实例?

[英]How can I get the mime-type of an Image class instance in memory in c#?

In a library I am writing for some infrastructure projects at work, I have a method to create various scales of an image (for thumbnails etc...). 在我正在为工作中的一些基础设施项目编写的库中,我有一种方法来创建图像的各种比例(用于缩略图等...)。 However, the system that I am storing this data in is requiring a mime-type declared in the database for various reasons. 但是,我存储此数据的系统需要出于各种原因在数据库中声明的mime类型。

Is there a way to get a Mime type from the passed in c# Image class, or will I have to have external applications pass in the Mimetype along with the image? 有没有办法从传入的c# Image类中获取Mime类型,或者我是否必须将外部应用程序与图像一起传入Mimetype?

You can get the ImageFormat from the Image , and you can get the MIME type from the ImageCodecInfo . 您可以从Image获取ImageFormat ,并且可以从ImageCodecInfo获取MIME类型。 All you need to do is tie the two together: 你需要做的就是将两者结合在一起:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何在下载/上传 dropbbox 方法中获取文件 mime-type/content-type? - How can we get files mime-type/content-type in download/upload dropbbox methods? 我可以在C#中从“此”获取子类实例吗? - Can I get child class instance from `this` in C#? 如何获取ASP.NET C#中请求的文件的MIME类型? - How do I get the MIME type of a file being requested in ASP.NET C#? 如何使用C#获取在线文件的MIME类型 - How to get mime type of online files using c# 如何根据扩展名获取文件类型信息? (不是 MIME)在 C# - How do I get File Type Information based on extension? (not MIME) in c# UNITY C# - 如何获取标有自定义属性(字段)的 class 实例的所有字段? - UNITY C# - How can I get all the fields of the an instance of a class marked with my custom atribute(the fields)? 如何在C#中获取AxWebBrowser实例的屏幕截图? - How can I get a screenshot a the AxWebBrowser instance in C#? 如何获取C#中的总物理内存? - How can I get the total physical memory in C#? 如何获取分配给 C# 中抽象类的泛型列表中的对象类型? - How can I get the type an object in a generic list assigned to an abstract class in C#? 如何在非托管内存中实例化 C# 类? (可能的?) - How to instance a C# class in UNmanaged memory? (Possible?)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM