public DrawString ( string s, |
||
s | string | |
font | ||
brush | ||
point | ||
format | ||
return | void |
using System.Drawing; // Create new image object var bmp = new Bitmap(200, 100); // Get graphics object and set font using (var graphics = Graphics.FromImage(bmp)) using (var font = new Font("Arial", 16)) { // Draw string with text and position graphics.DrawString("Hello, world!", font, Brushes.Black, new PointF(10, 10)); } // Save image bmp.Save("output.bmp");
using System.Drawing; // Create new image object var bmp = new Bitmap(200, 100); // Get graphics object and set font using (var graphics = Graphics.FromImage(bmp)) using (var font = new Font("Arial", 16)) { // Draw string with text and position graphics.DrawString("Hello, world!", font, Brushes.Black, new PointF(10, 10)); graphics.DrawString("Goodbye, world!", font, Brushes.Red, new PointF(10, 40)); } // Save image bmp.Save("output.bmp");This example is similar to the first one, but instead draws two different text strings with different brush colors. The first text is still drawn in black, but the second text is drawn in red. Both examples utilize the System.Drawing package library.
public DrawString ( string s, |
||
s | string | |
font | ||
brush | ||
point | ||
format | ||
return | void |