判断指定文件是否为图片

  /// <summary>
        /// 判断指定文件是否为图片
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static bool IsImage(Stream stream)
        {
            try
            {
                System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
            finally
            {
                stream.Seek(0, SeekOrigin.Begin);  
            }
        }

  

posted @ 2017-05-22 09:13  雨姗  阅读(461)  评论(0编辑  收藏  举报