/// <summary> /// Resize an image /// </summary> /// <param name="source"></param> /// <param name="parameters"></param> /// <returns></returns> public virtual Bitmap Resize(object source, ResizeSettings parameters) { using (var job = new ImageJob(source)) { var layout = _imageLayoutBuilder.BuildLayout(job.Bitmap.Size, parameters); var bmp = new Bitmap((int)layout.CanvasSize.Width, (int)layout.CanvasSize.Height, PixelFormat.Format24bppRgb); var gfx = Graphics.FromImage(bmp); gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.CompositingQuality = CompositingQuality.HighQuality; gfx.CompositingMode = CompositingMode.SourceOver; // white background gfx.FillRectangle(new SolidBrush(Color.White), 0, 0, layout.CanvasSize.Width, layout.CanvasSize.Height); // draw the image gfx.DrawImage(job.Bitmap, layout.Image, new RectangleF(0, 0, job.Bitmap.Width, job.Bitmap.Height), GraphicsUnit.Pixel); // commit gfx.Flush(FlushIntention.Flush); gfx.Dispose(); return(bmp); } }
/// <summary> /// Resize an image /// </summary> /// <param name="source"></param> /// <param name="parameters"></param> /// <returns></returns> public virtual Bitmap Resize(object source, ResizeSettings parameters) { using (var job = new ImageJob(source)) { var layout = _imageLayoutBuilder.BuildLayout(job.Bitmap.Size, parameters); var bmp = new Bitmap((int)layout.CanvasSize.Width, (int)layout.CanvasSize.Height, PixelFormat.Format24bppRgb); var gfx = Graphics.FromImage(bmp); gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; gfx.SmoothingMode = SmoothingMode.HighQuality; gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; gfx.CompositingQuality = CompositingQuality.HighQuality; gfx.CompositingMode = CompositingMode.SourceOver; // white background gfx.FillRectangle(new SolidBrush(Color.White), 0, 0, layout.CanvasSize.Width, layout.CanvasSize.Height); // draw the image gfx.DrawImage(job.Bitmap, layout.Image, new RectangleF(0,0, job.Bitmap.Width, job.Bitmap.Height), GraphicsUnit.Pixel); // commit gfx.Flush(FlushIntention.Flush); gfx.Dispose(); return bmp; } }