protected static Image ThumailImage( string sourcePah, int thumbWidth, int thumbHeight) ... { int width = thumbWidth; int height = thumbHeight; FileStream source = new FileStream(file, FileMode.Open); System.Drawing.Image img = System.Drawing.Image.FromStream(source); if (img.Width / width > img.Height / height) ...{ height = img.Width * height / img.Width; } else ...{ width = img.Height * width / img.Height; } System.Drawing.Image thumbImage = System.Drawing.Image.FromHbitmap(new Bitmap(thumbWidth, thumbHeight, PixelFormat.Format32bppRgb).GetHbitmap()); Graphics graphics = Graphics.FromImage(thumbImage); SolidBrush brush = new SolidBrush(Color.White); graphics.FillRectangle(brush, 0, 0, thumbWidth, thumbHeight); graphics.DrawImage(img, (thumbWidth - width) / 2, (thumbHeight - height) / 2, width, height); graphics.Dispose(); source.Close(); return thumbImage; }