获取图像的缩略图

using System.Drawing;
using System.Drawing.Imaging
        public static void SmallPic(string stroldPic,string strnewPic,int intWidth, int intHeight)
        {

         System.Drawing.Image oldimage = System.Drawing.Image.FromFile(stroldPic);
         System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(intWidth, intHeight,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
         Bitmap output=new Bitmap(thumbnailImage);

         ImageCodecInfo[] codecs=ImageCodecInfo.GetImageEncoders();
         ImageCodecInfo ici=null;
         foreach(ImageCodecInfo codec in codecs){if(codec.MimeType=="image/jpeg")ici=codec;}
         EncoderParameters ep=new EncoderParameters();
         ep.Param[0]=new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,(long)100);
         output.Save(strnewPic,ici,ep);


         ep.Dispose();
         output.Dispose();
         oldimage.Dispose();
         thumbnailImage.Dispose();
         System.IO.File.Delete(stroldPic);
        }
        private static bool ThumbnailCallback()
        {
         return false;
        }

 

 

 

 

改进后:

public Bitmap SmallPic(Image img, int intWidth, int intHeight)
        {
            Image thumbnailImage = img.GetThumbnailImage(intWidth, intHeight, new Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
            Bitmap output = new Bitmap(thumbnailImage);
            return output;
        }
        private bool ThumbnailCallback()
        {
            return false;
        }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值