码迷,mamicode.com
首页 > Windows程序 > 详细

C#获取图片扩展名

时间:2017-06-16 16:50:31      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:扩展   ima   style   log   format   private   uid   sed   image   

代码:

技术分享
private string GetImageExtension(MemoryStream ms)
{
    try
    {
        Image image = Image.FromStream(ms);

        if (image.RawFormat.Guid == ImageFormat.Bmp.Guid) return ".bmp";
        if (image.RawFormat.Guid == ImageFormat.Emf.Guid) return ".wmf";
        if (image.RawFormat.Guid == ImageFormat.Exif.Guid) return ".exif";
        if (image.RawFormat.Guid == ImageFormat.Gif.Guid) return ".gif";
        if (image.RawFormat.Guid == ImageFormat.Icon.Guid) return ".icon";
        if (image.RawFormat.Guid == ImageFormat.Jpeg.Guid) return ".jpg";
        if (image.RawFormat.Guid == ImageFormat.MemoryBmp.Guid) return ".bmp";
        if (image.RawFormat.Guid == ImageFormat.Png.Guid) return ".png";
        if (image.RawFormat.Guid == ImageFormat.Tiff.Guid) return ".tiff";
        if (image.RawFormat.Guid == ImageFormat.Wmf.Guid) return ".wmf";

        return string.Empty;
    }
    catch
    {
        return string.Empty;
    }
}
View Code

 

C#获取图片扩展名

标签:扩展   ima   style   log   format   private   uid   sed   image   

原文地址:http://www.cnblogs.com/s0611163/p/7027729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!