代码:

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;
}
}

C#获取图片扩展名的更多相关文章

  1. C#根据byte前两位获取图片扩展名

    C#根据byte前两位获取图片扩展名 /// <summary> /// 根据byte前两位获取图片扩展名 /// </summary> /// <param name= ...

  2. PHP获取文件扩展名的多种方法

    PHP获取文件扩展名的N种方法. 第1种方法: function get_extension($file) { substr(strrchr($file, '.'), 1): } 第2种方法: fun ...

  3. python获取文件扩展名的方法(转)

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...

  4. python获取文件扩展名的方法

    主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...

  5. PHP中获取文件扩展名的N种方法

    PHP中获取文件扩展名的N种方法 从网上收罗的,基本上就以下这几种方式: 第1种方法:function get_extension($file){substr(strrchr($file, '.'), ...

  6. PHP获取文件扩展名五种以上的方法和注释

    在PHP面试中或者考试中会有很大几率碰到写出五种获取文件扩展名的方法,下面是我自己总结的一些方法 $file = ‘需要进行获取扩展名的文件.php’; //第一种,根据.拆分,获取最后一个元素的值f ...

  7. PHP中获取文件扩展名

    function get_extension($file) { return substr(strrchr($file, '.'), 1) ; } function get_extension($fi ...

  8. PHP获取文件扩展名的五种方式

    这是我应聘实习时遇到的一道笔试题: 使用五种以上方式获取一个文件的扩展名. 要求:dir/upload.image.jpg,找出 .jpg 或者 jpg , 必须使用PHP自带的处理函数进行处理,方法 ...

  9. PHP 获取文件扩展名的五种方式

    第一种 substr(strrchr("http://www.xxx.com/public/abc.jpg", '.'), 1); string strrchr('string', ...

随机推荐

  1. selenium webdriver——JS滚动到指定位置

    1.DOM滚动方法 1.scrollIntoView(alignWithTop)  滚动浏览器窗口或容器元素,以便在当前视窗的可见范围看见当前元素.如果alignWithTop为true,或者省略它, ...

  2. 利用MemoryAnalyzer进行OutOfMemoryError的诊断分析

    这篇帖子只介绍利用MemoryAnalyzer进行简单的JVM的堆的分析,至于JVM的内部结构是怎么样的,这里不进行分析.好吧,废话不多说:首先如果我们要分析JVM某个时刻的Heap的对象分配情况,我 ...

  3. 迷你MVVM框架 avalonjs 学习教程9、类名操作

    ms-class是avalon用得最多的几个绑定之一,也正因为如此其功能一直在扩充中.根据时期的不同,分为旧风格与新风格两种. 旧风格是指ms-class-xxx=”expr”,*ms-class-a ...

  4. 初步认识session

    TestSession01.java protected void doPost(HttpServletRequest request, HttpServletResponse response) t ...

  5. Grapher - Change how graphs look

    [Change how graphs look] Pan and zoom the graph 工具条如下: Change the type of graph 开场的Graph Template在Me ...

  6. java web作用域page request session application

    转载自:http://blog.csdn.net/wyd458549392147/article/details/6944481 1.page指当前页面.只在一个jsp页面里有效 . 2.reques ...

  7. 安装labelImg

    上篇文章,我提到了安装这个工具时,遇到pyqt与sip版本不匹配的未解决问题,最后是通过windows版本一键实现的,工具包见下面链接. 参考:http://blog.csdn.net/jesse_m ...

  8. 使用javascript,jquery实现的图片轮播功能

    使用javascript,jquery实现的图片轮播功能本功能采用最基础的javascript和一些简单的jquery技术实现,易理解,以修改使用,代码简易,适合刚开始接触到网站开发的朋友们参考.可以 ...

  9. import c++ project to eclipse cdt with exiting makefile

    Step 2: You are now ready to build your project. To build your project, select Project > Build Pr ...

  10. 配置Linux防火墙

    配置防火墙(服务器安全优化)(转) 安全规划:开启 80  22 端口并 打开回路(回环地址 127.0.0.1) # iptables –P INPUT ACCEPT # iptables –P O ...