Add Highlight Annotation to JPG using Java

Images often serve as powerful communicators, conveying information in a visual language. Adding annotations to images can significantly enhance their value and usability. In this tutorial, we will explore the process of how to add highlight annotation to JPG using Java, providing you with a comprehensive guide to seamlessly integrate this functionality into your projects. Following steps and code example shows how to make highlight annotation in Java for JPG.

Steps to Add Highlight Annotation to JPG using Java

  1. Configure your Integrated Development Environment (IDE) to utilize GroupDocs.Annotation for Java, enabling the integration of a highlight annotation into a JPG image
  2. Create an instance of the Annotator class by providing the JPG file path as a parameter to its constructor
  3. Instantiate the HighlightAnnotation class and define the necessary properties, such as BackgroundColor, Opacity, and position
  4. Call the Annotator.add method, passing the HighlightAnnotation object as an argument
  5. Call the Annotator.save method to save the resulting JPG output to the disk

By following these steps, you can seamlessly insert highlight annotation in JPG using Java. As you explore the idea of highlighting text in images, remember that this approach makes things easier and ensures that it works well on different types of computers. It’s a useful tool for developers who want to enhance how they handle images. These steps work on popular systems like Windows, macOS, and Linux, all of which support Java. You don’t need to install any extra software to add highlighted notes to a JPG file.

Code to Add Highlight Annotation to JPG using Java

import com.groupdocs.annotation.Annotator;
import com.groupdocs.annotation.licenses.License;
import com.groupdocs.annotation.models.Point;
import com.groupdocs.annotation.models.annotationmodels.HighlightAnnotation;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
public class AddHighlightAnnotationtoJPGUsingJava {
public static void main(String[] args) {
// Set License to avoid the limitations of Annotation library
License license = new License();
license.setLicense("GroupDocs.Annotation.lic");
// Create an instance of Annotator class
Annotator annotator = new Annotator("input.jpg");
Point point1 = new Point(80, 730);
Point point2 = new Point(240, 730);
Point point3 = new Point(80, 650);
Point point4 = new Point(240, 650);
List<Point> points = new ArrayList<Point>();
points.add(point1);
points.add(point2);
points.add(point3);
points.add(point4);
// Create an instance of HighlightAnnotation class and set options
HighlightAnnotation highlight = new HighlightAnnotation();
highlight.setBackgroundColor(65535);
highlight.setCreatedOn(Calendar.getInstance().getTime());
highlight.setFontColor(0);
highlight.setMessage("This is highlight annotation");
highlight.setOpacity(0.5);
highlight.setPageNumber(0);
highlight.setPoints(points);
// Add highlight annotation
annotator.add(highlight);
// Save JPG to disk
annotator.save("output.jpg");
}
}

In conclusion, the process of adding highlight annotations to JPG images using Java offers a dynamic way to enhance and customize your visual content. Whether you’re creating educational materials, documentation, or simply adding emphasis to certain aspects of an image, the ability to programmatically annotate JPG files opens up a world of possibilities. After you’ve installed the annotation library and adjusted the file paths as needed, adding the code to your applications is an easy job. Great job! Now you know how to create highlight annotation in JPG using Java.

We’ve published an article before, guiding you through the steps to include ellipse annotations in JPG images. For more details, please refer to our guide on how to add ellipse annotation to JPG using Java.

 English