代码:

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. ubuntu,debian root密码忘记破解

    开机启动的时候在grub引导时,按住e进行启动项编辑,修改开头有linux字符及最后又ro字符的行,将ro字符改为rw single init=/bin/bash按F10键进行启动即可进入单用户模式, ...

  2. ASP.NET AJAX web chat application

    ASP.NET AJAX web chat application The project illustrates how to design a simple AJAX web chat appli ...

  3. <form> 表单提交 return 阻止内容为空事件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Dirichlet Process

    http://www.cnblogs.com/zhangbojiangfeng/p/5962039.html [各种函数推导]

  5. springboot+shiro+jwt

    1.添加依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-sp ...

  6. Navigation and Pathfinding

    [Navigation and Pathfinding] 术语: 1)NavMesh 2)NavMesh Agent 3)Off-Mesh Link 4)NavMesh Obstacle A comm ...

  7. cookie的长度和限制数量

    一.浏览器允许每个域名所包含的 cookie 数 Microsoft 指出 Internet Explorer 8 增加 cookie 限制为每个域名 50 个,但 IE7 似乎也允许每个域名 50 ...

  8. Tomcat 用startup.bat启动,卡住解决

    相比较用eclipse发布项目,直接在tomcat的bin目录下用startup.bat启动需要多做一些工作,而且直接运行startup.bat不会报错,不利于解决问题 所以最好的选择是在安装部署时 ...

  9. Codeforces Beta Round #9 (Div. 2 Only) D. How many trees? dp

    D. How many trees? 题目连接: http://www.codeforces.com/contest/9/problem/D Description In one very old t ...

  10. jquery的理解

    1.jquery的好处 简化js的复杂操作 不再需要关心兼容性 提供大量使用方法 2.jquery的设计思想 选择网页元素 -模拟css选择元素 -独有的表达式选择 -多种筛选方法 写法 -方法函数化 ...