Add Watermark to Images using Java

Add Watermark to Images using Java

The global market has become so open and vigilant in this fast-growing world. The security of your digital assets has become a serious concern. Hence, your business images need to have a mark of your ownership to avoid any possibility of theft or forgery. However, in this blog post, we will learn how to add watermark to images using Java imaging library. By the end of this guide, you will be able to build a watermark creator programmatically for your Java application.

The following sections will be covered:

Java imaging library installation

Adding a watermark to popular image formats programmatically is a matter of a few lines of source code. Therefore, you can download the API’s JAR file or install using the following configurations.

    <name>Aspose Java API</name>

Add watermark to images using Java

Now, let’s write a few lines of source code using methods exposed by this Java imaging library. There is a long list of methods available that you can see here.

Please follow the steps and the code snippet:

  1. Create an instance of an Image class and load an existing image.
  2. Create and initialize an instance of the Graphics class with the source image.
  3. Now, instantiate an instance of the Font class and set the font settings.
  4. Create an instance of SolidBrush class that is intended for drawing continuously with a specific color.
  5. Invoke the setColor method to set the brush color.
  6. Initialize an object of StringFormat class that encapsulates text layout information.
  7. Set text alignment information in the center of the vertical plane by calling the setAlignment method.
  8. Set formatting information by calling the setFormatFlags method.
  9. Draw a String using the drawString object and Font, at a specific Point.
  10. Call the save method to save the image with changes.

Copy & paste the following code into your main file:

You can see the output in the image below:

watermark creator

Get a Free License

You can avail a free temporary license to try the API without evaluation limitations.

Summing up

Finally, you have learned how to add watermark to images using Java. This blog post will really help you if you are looking to develop a watermark creator for your business software. In addition, you may visit the documentation to know the advanced features of this Java imaging library.

Moreover, we suggest you follow our Getting Started guide.

Finally, is writing new blog posts. Therefore, please stay in touch for regular updates.

Ask a question

You can let us know about your questions or queries on our forum.


How do you create a watermark in Java?

Please follow this link to know the code snippet and the steps that demonstrate how to add watermark to images programmatically.

See Also