Tuesday, March 15, 2011

C# Snippet Tutorial - How to Draw Text on an Image

In this snippet tutorial we're going to be adding on to our series of C# image editing tutorials. This tutorial is going to provide the code required to do basic text drawing including anti-aliasing and text alignment.
For more information on C# image editing, check out our previous two tutorials: C# Tutorial - Image Editing: Saving, Cropping, and Resizing and C# Tutorial - Image Editing: Rotate.
Ok, let's get started. The first thing we need to do is get a Bitmap object from an image file.
Bitmap myBitmap = new Bitmap("C:\\myImage.jpg");
Now that we have a Bitmap object we can get a Graphics object from it. The Graphics object will be doing all of our text drawing.