获取图片格式(不通过文件名后缀)

     /// <summary>
   /// 返回图片格式(和文件名后缀无关)
        /// </summary>
        /// <param name="strImgPath">图片路径及名称</param>
        /// <returns>jpeg\gif\bmp\png\tif\icon\wmf</returns>
        string GetImageFormat(string strImgFilePath)
        {
            string strImgFormat = "";
            System.Drawing.Image imgSrc = System.Drawing.Image.FromFile(strImgFilePath);

            if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
                strImgFormat = "jpeg";
            else if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
                strImgFormat = "gif";
            else if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Bmp))
                strImgFormat = "bmp";
            else if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
                strImgFormat = "png";
            else if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Tiff))
                strImgFormat = "tiff";
            else if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Icon))
                strImgFormat = "icon";
            else if (imgSrc.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Wmf))
                strImgFormat = "wmf";

            return strImgFormat;

        }

posted @ 2009-06-02 09:57  乔治国  阅读(1368)  评论(0编辑  收藏  举报