Write Text on JPG in C#

This article guides on how to write text on JPG in C#. It has the IDE settings, a list of steps, and a detailed sample code demonstrating how to add text to a JPG file in C#. You will learn to decorate the text in the JPG by setting various text properties and image backgrounds.

Steps to Add Text to JPG in C#

  1. Set the environment to use Aspose.Drawing for .NET to render text on JPG
  2. Create the Bitmap object and use it in creating a Graphics object for drawing on it
  3. Customize the Graphics object to set the rendering quality
  4. Define the background gradient colors in the Graphics object
  5. Create a font and draw the string twice for a shadow effect
  6. Draw an optional border around the text and save it on the disk

These steps describe how to add text in JPG file in C#. You can draw text using the DrawString() method by creating the bitmap, linking it with the Graphics object, and creating a brush, font, and bounding rectangle. Optional settings are setting the rendering quality, background gradient colors, and text style.

Code to Insert Text in JPG in C#

This code has demonstrated how to add text to a JPEG file in C#. For adding gradient color, we have used LinearGradientBrush which takes starting position, ending position, starting color, and ending color for the gradient. To add the shadow effect, the target string is painted twice with different colors.

This article has taught us the process of creating a JPEG image and adding decorated text to it. For scaling images, refer to the article on Scale image in C#.

 English