通过Image对象获取对象的格式

//strImgFilePath  图片文件名

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-09-15 18:02  kk.1230  阅读(562)  评论(0编辑  收藏  举报