using System.Drawing.Imaging; public void ResizePic(string oldFilePath, int thumbnailImageWidth, int thumbnailImageHeight, string targetFilePath) { using (Image oldImg = Image.FromFile(oldFilePath)) { using (Image thumnailImg = oldImg.GetThumbnailImage(thumbnailImageWidth, thumbnailImageHeight, null, IntPtr.Zero)) { ImageCodecInfo imgCodeInfo = GetImageCodeInfo("image/jpeg"); if (imgCodeInfo != null) { EncoderParameters encodeParameters = new EncoderParameters(1); encodeParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100); Bitmap bmp = new Bitmap(thumnailImg); encodeParameters.Dispose(); encodeParameters = null; bmp.Save(targetFilePath, imgCodeInfo, encodeParameters); bmp.Dispose(); } } } } private static ImageCodecInfo GetImageCodeInfo(string mimeType) { ImageCodecInfo[] encoders; encoders = ImageCodecInfo.GetImageEncoders(); for (int i = 0; i < encoders.Length; i++) { if (encoders[i].MimeType == mimeType) return encoders[i]; } return null; }