
Writing text on JPG images enhances branding and lets you add context, watermarks, or copyright information. Whether you’re creating memes, social media posts, or marketing materials, the ability to write text on JPG images is incredibly useful. In this post, we’ll show how to add text to JPG images using Java, guiding you step‑by‑step. Let’s dive in!
This article covers the following topics:
- Java API to write text on JPG images
- Write text on JPG images in Java
- Add captions to photos in Java
- Write text on JPG images online
- Free resources
Java API to Write Text on JPG Images
We will use Aspose.Drawing for Java to write text on JPG images. Aspose.Drawing for Java is a robust 2D graphics library that enables developers to create and manipulate vector graphics, images, and drawings within Java applications. It provides APIs for rendering graphics, drawing shapes, and handling fonts, allowing high‑quality graphical content creation and manipulation.
Please download the JAR of the API or add the following pom.xml configuration in a Maven‑based Java application.
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-drawing</artifactId>
<version>24.4</version>
</dependency>
</dependencies>
Write Text on JPG Images in Java
We can easily write any kind of text on JPG images by following these steps:
- Load a JPG image using the Bitmap class.
- Create a Graphics object from the bitmap with fromImage().
- Initialize a SolidBrush with the desired text color.
- Define a Font with the required family, style, and size.
- Create a Rectangle that defines the text area.
- Call drawString() with the text, font, brush, and rectangle.
- Save the output image using save().
The following code sample shows how to write text on JPG in Java.

Write Text on JPG Images in Java
Add Caption to Photos - Add Text to Photo
You can also add a caption to a photo by following these steps:
- Load a photo using the Bitmap class.
- Create a new bitmap that includes extra space for the caption rectangle.
- Create a Graphics object from the new bitmap with fromImage().
- Draw the original photo onto the new bitmap using drawImage().
- Draw a filled rectangle for the caption background.
- Set up text formatting with the StringFormat class.
- Define the caption text, its color, and font.
- Call drawString() with the text, font, brush, and rectangle.
- Save the final image using save().
The following code sample shows how to add a caption to a photo in Java.

Add caption to photos in Java
Get a Free License
You can obtain a free temporary license to try Aspose.Drawing for Java without any evaluation limitations.
Write Text on JPG Images Online
You can also try a free online tool to write text on JPG images. Its user‑friendly interface lets you add text to images without installing software, creating an account, or subscribing to a service.

Add Text to Image – Free Learning Resources
In addition to writing text on JPG images, explore the resources below to learn more about adding text to images, displaying vector graphics on raster images, and discovering other features of the library:
Conclusion
In this post, we showed how to write text on JPG images in Java. Whether you need simple captions, dynamic banners, or watermarks for branding, Aspose.Drawing for Java offers the tools and flexibility to achieve professional results. By following the steps above, you can add text, customize fonts, colors, and positions, and use a free online tool for quick edits. For any questions, feel free to contact us on our free support forum.