Tag Archives: GDI+

.Net Graphics: drawing text on a bitmap

I use this code here.

Graphics backgroundGraphics;
backgroundImage = (Bitmap)Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\images\Header.jpg");
backgroundGraphics = Graphics.FromImage(backgroundImage);
var font = new Font("Perpetua Titling MT", 24F, FontStyle.Regular);
backgroundGraphics.DrawString(authorname.ToUpper(), font, new SolidBrush(Color.FromArgb(100, 0, 0, 0)), 10, 5);

Now save – or output to the browser:

backgroundImage.Save(context.Response.OutputStream, ImageFormat.Jpeg);