using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Drawing2D; public class Graphix { public static System.Drawing.Image GetSizedImage(string filename, int width) { Bitmap loBmp = new Bitmap(filename); int sourceWidth = loBmp.Width; int sourceHeight = loBmp.Height; int destWidth = width; int destHeight = (int)((destWidth / (double)sourceWidth) * sourceHeight); System.Drawing.Bitmap bmpOut = new Bitmap(destWidth, destHeight); Graphics g = Graphics.FromImage(bmpOut); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.FillRectangle(Brushes.White, 0, 0, destWidth, destHeight); g.DrawImage(loBmp, 0, 0, destWidth, destHeight); loBmp.Dispose(); return bmpOut; } public static System.Drawing.Image GetSizedImage(string filename, int width, int height) { return GetSizedImage(filename, width, height, false); } public static System.Drawing.Image GetSizedImage(string filename, int width, int height, bool noStretch) { Bitmap loBmp = new Bitmap(filename); int sourceWidth = loBmp.Width; int sourceHeight = loBmp.Height; int destX = 0; int destY = 0; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; nPercentW = ((float)width / (float)sourceWidth); nPercentH = ((float)height / (float)sourceHeight); if (nPercentH < nPercentW) { nPercent = nPercentH; destX = System.Convert.ToInt16((width - (sourceWidth * nPercent)) / 2); } else { nPercent = nPercentW; destY = System.Convert.ToInt16((height - (sourceHeight * nPercent)) / 2); } int destWidth = (int)(sourceWidth * nPercent); int destHeight = (int)(sourceHeight * nPercent); System.Drawing.Bitmap bmpOut = new Bitmap(width, height); Graphics g = Graphics.FromImage(bmpOut); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.FillRectangle(Brushes.White, 0, 0, width, height); g.DrawImage(loBmp, destX, destY, destWidth, destHeight); loBmp.Dispose(); return bmpOut; } }