public Bitmap GetThumbnail(int width, int height, Color background, Color border, int borderWidth) { lock (this) { Bitmap thumb = new Bitmap(width, height); Graphics g = Graphics.FromImage(thumb); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Renderer.GdiRenderer r = new Renderer.GdiRenderer(g); g.Clear(background); float isRatio = Format.Width / Format.Height; float shouldRatio = width / (float)height; float scale = 1; SizeF ps = Format.GetPixelSize(); if (isRatio > shouldRatio) { float w = ps.Width; scale = width / w; } else { float h = ps.Height; scale = height / h; } g.TranslateTransform((width - ps.Width * scale) / 2, (height - ps.Height * scale) / 2); g.ScaleTransform(scale, scale); if (this.BackgroundImage != null) { r.DrawImage(BackgroundImage, new RectangleF(new PointF(0, 0), Format.GetPixelSize())); } Color bakCol = this.BackgroundColor1; this.BackgroundColor1 = Color.Transparent; this.Draw(r); this.BackgroundColor1 = bakCol; g.ResetTransform(); using (Pen p = new Pen(border, borderWidth)) { g.DrawRectangle(p, new Rectangle(borderWidth / 2, borderWidth / 2, width - borderWidth, height - borderWidth)); } return(thumb); } }
public override void DrawImage(Image img, RectangleF rect) { r.DrawImage(img, rect); }