code_junkie

Using custom TTF font for Image rendering

Nov 14th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. using (var backgroundImage = new Bitmap(backgroundPath))
  2. using (var avatarImage = new Bitmap(avatarPath))
  3. using (var myFont = new Font("myCustom", 8f))
  4. {
  5. Graphics canvas = Graphics.FromImage(backgroundImage);
  6. canvas.DrawImage(avatarImage, new Point(0, 0));
  7.  
  8. canvas.DrawString(username, myFont,
  9. new SolidBrush(Color.Black), new PointF(5, 5));
  10.  
  11. return new Bitmap(backgroundImage);
  12. }
  13.  
  14. // 'PrivateFontCollection' is in the 'System.Drawing.Text' namespace
  15. var foo = new PrivateFontCollection();
  16. // Provide the path to the font on the filesystem
  17. foo.AddFontFile("...");
  18.  
  19. var myCustomFont = new Font((FontFamily)foo.Families[0], 36f);
Add Comment
Please, Sign In to add comment