public override void RenderTo(Resizing.ImageState s) { if (string.IsNullOrEmpty(Path)) { return; } s.destGraphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; s.destGraphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; s.destGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; Bitmap img = null; if (this.ShouldLoadAsOriginalSize()) { img = GetMemCachedBitmap(Path, ImageQuery); } //Calculate the location for the bitmap RectangleF imgBounds = this.CalculateLayerCoordinates(s, delegate(double maxwidth, double maxheight) { ResizeSettings opts = new ResizeSettings(ImageQuery); if (Fill && string.IsNullOrEmpty(opts["scale"])) { opts.Scale = ScaleMode.Both; } if (!double.IsNaN(maxwidth)) { opts.MaxWidth = (int)Math.Floor(maxwidth); } if (!double.IsNaN(maxheight)) { opts.MaxHeight = (int)Math.Floor(maxheight); } if (img == null) { img = GetMemCachedBitmap(Path, opts); //Delayed creation allows the maxwidth/maxheight to be used in gradient plugin } lock (img) { return(ImageBuilder.Current.GetFinalSize(img.Size, opts)); } }, true); lock (img) { //Only one reader from the cached bitmap at a time. //Skip rendering unless we have room to work with. if (imgBounds.Width < 2 || imgBounds.Height < 2) { return; } if (ImageQuery.Keys.Count > 0 || Fill) { ResizeSettings settings = new ResizeSettings(ImageQuery); if (Fill && string.IsNullOrEmpty(settings["scale"])) { settings.Scale = ScaleMode.Both; } settings.MaxWidth = (int)Math.Floor(imgBounds.Width); settings.MaxHeight = (int)Math.Floor(imgBounds.Height); using (Bitmap final = ImageBuilder.Current.Build(img, settings, false)) { s.destGraphics.DrawImage(final, PolygonMath.ToRectangle(PolygonMath.CenterInside(PolygonMath.DownScaleInside(final.Size, imgBounds.Size), imgBounds))); } } else { s.destGraphics.DrawImage(img, PolygonMath.ToRectangle(PolygonMath.CenterInside(PolygonMath.DownScaleInside(img.Size, imgBounds.Size), imgBounds))); } } }