压缩图片

 public void CreateThumbnailImage() 

 { 

     string imgFile = "e:/test.jpg"; 

     System.Drawing.Image img = System.Drawing.Image.FromFile(imgFile); 

     System.Drawing.Image.GetThumbnailImageAbort cb = new System.Drawing.Image.GetThumbnailImageAbort(CallBack); 

     System.Drawing.Image thumbnailImage = img.GetThumbnailImage(120, 120, cb, System.IntPtr.Zero); 

     string extendName = imgFile.Substring(imgFile.LastIndexOf(".") + 1); 

     ImageFormat imgFormat = GetImageFormat(extendName); 

     thumbnailImage.Save("e:/result.jpg",imgFormat); 

 } 

 

 public bool CallBack() 

 { 

     return     false; 

 }

 

 

 //获得图片格式 

        private static ImageFormat GetImageFormat(String extendName)
        {
            extendName = extendName.ToLower();
            switch (extendName)
            {
                case "gif":
                    return ImageFormat.Gif;
                case "jpg":
                case "jpeg":
                    return ImageFormat.Jpeg;
                case "bmp":
                    return ImageFormat.Bmp;
                case "wmf":
                    return ImageFormat.Emf;
                case "exif":
                    return ImageFormat.Exif;
                case "icon":
                    return ImageFormat.Icon;
                case "tiff":
                    return ImageFormat.Tiff;
                default:
                    return ImageFormat.Png;
            }
        }

posted @ 2010-06-29 09:01 Ame 阅读(...) 评论(...) 编辑 收藏