Skip to content

Instantly share code, notes, and snippets.

@GeradeDev
Created July 29, 2020 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeradeDev/2cf062805b52ebe0b2e4468ad9de6856 to your computer and use it in GitHub Desktop.
Save GeradeDev/2cf062805b52ebe0b2e4468ad9de6856 to your computer and use it in GitHub Desktop.
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