Creating Aspose.Drawing Java application

You can use Aspose.Drawing library in a cross-platform Java applications to draw vector graphics, and text, and generate images as demonstrated in this tutorial.

Upon installation, all Aspose components operate in evaluation mode. This mode, which doesn’t have a time constraint, incorporates watermarks into the generated drawings.

Creating an Application that Uses Aspose.Drawing

To work with Aspose.Drawing in your applications:

  • Download Aspose.Drawing for Java.
  • Create a project.
  • Add a reference to the Aspose.Drawing API.
  • Write the code.

Download Aspose.Drawing for Java

  • Download Aspose.Drawing for Java.
  • Unzip the downloaded ZIP archive on your development computer, for example, c:\Users\User\Aspose\aspose-drawing-java\Aspose.Drawing\target.

Create Project

  • Launch the IDE IntelliJ IDEA.
  • In the main toolbar click “New Project”.
  • Enter the project name and location.
  • Click “Create” button.

Add Reference of Aspose.Drawing for Java API

The project uses the Aspose.Drawing API as the core library for performing drawing operations. So, you have to reference the Aspose.Drawing JAR in the project.

  1. Select the “Project Structure” menu (in the File menu):
  1. Select the “Modules” in the “Project Settings”.

  2. Navigate to the “Dependencies” tab and click “+” to add a folder:

  1. Select the Aspose.Drawing the target folder with JAR file for adding it to the project:

Write Main.java

The next step is to create a new class.

By default, the Main.java file is created in the src/main/java/org.example folder inside the Project tree. Main.java file is ready for editing with the default class Main and method main().

The code below uses the Aspose.Drawing API to create a drawing from scratch. Replace the Main.java file with the following code that draws a gradient and saves an image:

Run Main.java in IDE to create drawing image

Run Java application

Start the project from IDE by pressing the “Run” button on the toolbar. In the project output directory, the resulting gradient.png image file will be generated:

Linear gradient drawing in Java

Linear gradient drawing in Java