This step-by-step tutorial explains how to write text on image using C#. You will learn to add text on image using C# without installing the font on the system. Other variations in the code to customize the rendering process will also be discussed in this article.
Steps to Add Text Over Image using C#
- Install Aspose.Font for .NET package from NuGet.org to draw text on an image
- Import the required namespaces for handling fonts and image options
- Load the license to avoid evaluation restrictions, such as a watermark
- Define the input font file and output image file paths
- Create the FontDefinition object by setting the font type and the TTF font file content
- Load the font as TtfFont using the Font.Open() method
- Call the DrawText() method to create a rendered text stream with loaded font, text, and font size
- Convert the stream to a Bitmap and save as a PNG image
These steps summarize the process to draw text on image in C#. Commence the program by loading the license, specifying the font file and output file names, and opening the target font using the FontDefinition object. It finally renders the text with the given font in a stream, converts the stream to a bitmap, and saves the bitmap as an image on the disk.
Code to Add Text to the Image using C#
The above sample code demonstrates the process to add text onto image using C#. The DrawText method has multiple overloads that render text into a bitmap and return the stream in PNG format. value, and maximum image width for wrapping.
This article has taught us the process of drawing text on an image without requiring font installation. To convert TTF to SVG, refer to the article on Convert TTF to SVG in C#.