[英]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.