Please find the following code to generate a thumbnail version of an image: public class ThumbnailGenerator { public void GenerateThumnail(int thumbWidth, string src, string dest) { try { using (System.Drawing.Image image = System.Drawing.Image.FromFile(src)) { int srcWidth = image.Width; int srcHeight = image.Height; int thumbHeight = Convert.ToInt32(Math.Round(Convert.ToDouble (Convert.ToDouble(srcHeight) / Convert.ToDouble(srcWidth) * thumbWidth), MidpointRounding.ToEven)); using (Bitmap bmp = new Bitmap(thumbWidth, thumbHeight)) { using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp)) { gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight); gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel); bmp.Save(dest, System.Drawing.Imaging.ImageFormat.Jpeg); } } } } catch { throw; } } } 解决方案 这篇关于C#缩略图图像生成,用于大型图像出现内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 11:30