using System.Drawing; using System.Windows.Forms; public class MyForm : Form { protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawString("Hello, world!", new Font("Arial", 12), Brushes.Black, new Point(10, 10)); } }
using System.Drawing; public static void Main() { Bitmap image = new Bitmap(200, 100); Graphics graphics = Graphics.FromImage(image); graphics.DrawString("Hello, world!", new Font("Arial", 12), Brushes.Black, new Point(10, 10)); image.Save("output.png"); }This code creates a new Bitmap image and uses the Graphics object to draw the string "Hello, world!" on the image using a specific font and color. The resulting image is saved to a file named "output.png".