Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
private static MemoryStream GenerateBlogPostMetaCardWithDescription(string description)
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
Bitmap newBitmap;
using (var bitmap = (Bitmap)LoadImageTemplate())//load the image file
using (Graphics graphics = Graphics.FromImage(bitmap))
using (Font arialFont = new Font("Arial", 22))
Rectangle rect1 = new Rectangle(20, 220, 550, 40);
graphics.DrawString(description, arialFont, Brushes.White, rect1, format);
newBitmap = new Bitmap(bitmap);
MemoryStream memoryStream = new MemoryStream();
newBitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
memoryStream.Position = 0;
return memoryStream;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.