Draw Circle Java

Drawing shapes on images is a common requirement in various applications, such as highlighting important areas or adding annotations. In this blog post, you will learn how to draw a circle in Java. This approach allows developers to easily manipulate and annotate images and documents in Java.

Make Circle Drawing in Java - API Configuration

You can draw circle on any image or document with a few lines of code. You only need to install Conholdate.Total for Java by pasting the following Maven configurations into the pom.xml file of your project:

<dependency>
<groupId>com.conholdate</groupId>
<artifactId>conholdate-total</artifactId>
<version>24.6</version>
<type>pom</type>
</dependency>

Why Draw Circles on Images?

Drawing circles on images can be useful in a variety of scenarios, such as:

  • Highlighting Specific Areas: For example, you might want to draw a circle around a person’s face or an object in an image.
  • Creating Annotations: Circles can be used to add visual annotations to images, making them more informative or easier to understand.
  • Visual Effects: Adding circles or other shapes can enhance the visual appeal of images.

Draw a Circle in Java

Let’s dive into the code to see how you can draw a circle using Java:

  • Initialize the Annotator: The first step is to create an instance of the Annotator class, which will be used to add annotations to the source file.

  • Set Circle Properties: Next, we create an instance of EllipseAnnotation, which represents a circular annotation.

The following properties are set:

  1. BackgroundColor: Sets the background color of the circle. The color is specified as an integer value.
  2. Box: Defines the position of the circle.
  3. CreatedOn: Sets the creation date of the annotation.
  4. Opacity: Sets the opacity level of the circle. Here the value of 0.7 means the circle will be 70% opaque.
  5. PenColor: Sets the color of the circle’s outline.
  6. PenStyle: Defines the style of the outline. PenStyle.DOT creates a dotted line.
  7. PenWidth: Sets the width of the outline.
  • Finally, the circle is added to the image by calling the add method of the Annotator class, and the modified image is saved as “circle.png”.

The sample code below shows how to draw a circle in Java:

Free Evaluation License

You may request a free temporary license to test different features offered by the API.

Wrapping Up

In this blog post, we demonstrated how to draw a circle in Java. The shared code snippet simplifies the process of adding annotations to images or documents alike, allowing developers to create visually rich applications with ease. Whether you’re highlighting areas in an image, adding annotations, or creating visual effects, the API provides the tools you need to get the job done efficiently. Whereas, if you want to discuss any custom requirements or use cases then please reach out to us at the forum.

FAQs

Can I save the output file in formats other than PNG?

Yes, you can save the output in various formats such as JPEG, BMP, or TIFF by specifying the desired format in the save method.

Does this support drawing on PDF documents?

Yes, it supports drawing annotations on a wide range of document formats, including PDF, Word, Excel, and more.

Can I automate the process of drawing circles on multiple images?

Yes, you can automate the process by looping through a collection of images and applying the annotation logic programmatically. This is especially useful for batch processing.

See Also