Draw Geometric Shapes in Java


  • This section will demonstrate why you should choose Aspose.PSD for Java to draw geometric shapes in Java programmatically.

Java Drawing Library Installation

  • We will walk through the steps to install this Java API.

Drawing Rectangle in Java - Code Sample

  • Here we will write a code sample that draws a rectangle using the classes and methods exposed by Aspose.PSD for Java.

Draw an Arc Programmatically - Code Sample

  • Likewise, this section will take you to the code snippet to draw an arc programmatically.

In the recent past, we implemented the functionality to draw shapes such as eclipses and lines using Aspose.PSD for Java. However, this blog post will go one step further and will show you how you can draw geometric shapes in Java. Luckily, you can do that programmatically using this Java drawing library as it is a complete package to work with shapes in a Java application. So, there is no extra requirement rather we can go straight to the installation and implementation sections.

Java Drawing Library Installation

Now, you can head over to this installation guide to see all the mentioned details. However, you can download the JAR file here.

Maven configurations:

java drawing library installation

Drawing Rectangle in Java - Code Sample

Once the installation is completed, you can follow the steps mentioned below:

  • Create an instance of BmpOptions class.
  • Invoke the setBitsPerPixel method to set the bits per pixel.
  • Create an instance of Image class and initialize it with the object of PsdImage class.
  • Instantiate an instance of the Graphics class with the object of the Image class.
  • Set the background color of the image by calling the getYellow method.
  • The drawRectangle method will draw a rectangle.
  • Export image to BMP file format by calling the save method.

The following code sample demonstrates how to draw rectangles using Aspose.PSD for Java: Output:

how to draw rectangles

Draw an Arc Programmatically - Code Sample

Similarly, you can draw an arc in Java by following the code snippet mentioned below:


Draw an Arc

Draw Geometric Shapes - Get a Free License

You can get a free temporary license to try this Java drawing library without evaluation limitations.

Summing up

To conclude, Aspose.PSD for Java offers a bunch of features in addition to drawing geometric shapes in Java. So, we have walked through how to create rectangles and arcs using this Java drawing library. Moreover, you can go through the documentation, and the API references to know explore further. Finally, aspose.com is in the continuous process of writing blog posts, so stay in touch for updates.

Feel Free to Reach Out

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

Frequently Asked Questions – FAQs

How to create an arc in Java?

You can achieve that by opting for Aspose.PSD for Java. Please visit this link to get the code snippet.

How do you draw a rectangle in Java?

This Java drawing library provides classes and methods to draw rectangle in Java. Moreover, you can see the implementation here.

See Also