[C#]
void scaleAndComment(Bitmap original, ref Bitmap scaled, string comment, SmoothingMode mode, Font comment_font)
{
using (Graphics g = Graphics.FromImage((Image)scaled))
{
g.SmoothingMode = mode;
g.DrawImage(original, 0, 0, scaled.Width, scaled.Height);
if (!String.IsNullOrEmpty(comment))
{
StringFormat sFormat = new StringFormat(StringFormat.GenericTypographic);
SizeF textArea = g.MeasureString(comment, comment_font, new PointF(0, 0), sFormat);
float lx = (scaled.Width - textArea.Width) / 2;
float ly = -8 + scaled.Height - textArea.Height;
PointF location = new PointF(lx, ly);
g.FillRectangle(System.Drawing.Brushes.Black, new RectangleF(location, textArea));
g.DrawString(comment, comment_font, System.Drawing.Brushes.White, location, sFormat);
}
}
}
void usage()
{
[..]
using (Bitmap original)
{
using (Bitmap scaled = new Bitmap(scaled_width, scaled_height))
{
scaleAndComment(original, ref scaled, "Comment", SmoothingMode.AntiAlias, new Font("Arial", 8))
[..]
}
}
}