Add Text to Image | Add Text to Photo | Write Text on Image

Adding text to images is a great way to add context, branding, or even just a little bit of fun. It can be used to create memes, social media posts, marketing materials, and more. In this blog post, we will learn how to add text to images in C#. We’ll take you through step-by-step instructions on how to write on photos or other images in JPG or PNG format. So let’s get started!

This article covers the following topics:

  1. C# API to Add Text to Images
  2. Add Text to JPG Images
  3. Add Text to PNG Images
  4. Add Caption to Photos
  5. Write Text on Image Online
  6. Add Text to Image – Learning Resources

C# API to Add Text to Images

We will use Aspose.Drawing for .NET to add text to images. It is a powerful and versatile 2D graphics library that allows developers to create and manipulate graphics in a wide variety of applications. Aspose.Drawing for .NET supports a wide range of image manipulation operations, such as cropping, resizing, rotating, flipping, and watermarking. It is a great choice for developers who need a cross-platform, high-performance graphics library for their .NET applications.

Please download the DLL of the API or install it using NuGet.

PM> Install-Package Aspose.Drawing

Add Text to JPG Image in C#

We can add text to JPG images by following the steps below:

  1. Load a JPG image using the Bitmap class.
  2. Create a new Graphics object from the Bitmap object using the FromImage() method.
  3. Initialize a SolidBrush class object with the specified text color.
  4. Define a Font class object with the desired font family, style and size for the text.
  5. Optionally, initializa a Rectangle object.
  6. After that, call the DrawString() method with the text to show, Font, Brush, and Rectangle class objects as arguments.
  7. Finally, save the output image using the Save() method.

The following code sample shows how to add text to a JPG image in C#.

Add text to JPG image in C#

Add text to JPG image in C#

Add Text to PNG Image in C#

Similarly, we can add text to PNG images by following the steps mentioned earlier. However, we need to load a PNG image in first step.

The following code sample shows how to add text to a PNG image in C#.

Add text to PNG image in C#

Add text to PNG image in C#

Add Caption to Photos - Add Text to Photo

We can also add a caption to photos by following the steps below:

  1. Load a photo image using the Bitmap class.
  2. Create a new bitmap with the size of loaded image with addition of a rectangle size for caption.
  3. Create a new Graphics object from the Bitmap object using the FromImage() method.
  4. Draw the loaded image on newly created image using the DrawImage() method.
  5. Draw a filled rectangle for caption box.
  6. Specify the text string format using the StringFormat class.
  7. Define text, its color, and font
  8. After that, call the DrawString() method with the text to show, Font, Brush, and Rectangle class objects as arguments.
  9. Finally, save the output image using the Save() method.

The following code sample shows how to add a caption to a photo in C#.

Add caption to photos in C#

Add caption to photos in C#

Get Free License

You can get a free temporary license to try Aspose.Drawing for .NET without evaluation limitations.

Write Text on Image Online

You may also try a free add text to image online web app. Its user-friendly interface makes it easy and simple to write text on images without installing any extra software, creating an account, or subscribing to anything.

Add Text to Image – Free Learning Resources

You can learn more about adding text to images and displaying vector graphics on raster images, along with various other features of the library, using the resources below:

Conclusion

In this blog post, we’ve shown you how to add text to images in C#. We’ve covered the basics as well as some more advanced techniques for writing text on photos and images programmatically. Furthermore, we’ve introduced a free online tool for adding text to images on the go. In case of any ambiguity, please feel free to contact us on our free support forum.

See Also