Usage:
Code Snippet
- {
- using (Graphics g = Graphics.FromImage(b))
- {
- {
- {
- string textLabel = "Hello From TutorialGenius.com!";
- // Example - Black background
- this.ApplyText(g, textLabel, fontText, fontTextBrush, fontTextPoint, Color.Black);
- // Example - No background
- this.ApplyText(g, textLabel, fontText, fontTextBrush, fontTextPoint);
- }
- }
- }
- }
End of Code Snippet
Code Snippet
- // Applies a text layer with optional background onto a Graphics object
- private void ApplyText(Graphics g, string text, Font font, Brush brush, PointF? point = null, Color? backgroundColor = null)
- {
- // First - Apply optional background color
- if (backgroundColor.HasValue)
- {
- SizeF fontTextSize = g.MeasureString(text, font);
- g.FillRectangle(fillBrush, point.Value.X, point.Value.Y, fontTextSize.Width, fontTextSize.Height);
- }
- // Second - Draw string on graphics object
- g.DrawString(text, font, brush, point.Value);
- }
End of Code Snippet
No comments:
Post a Comment