Create bitmap from scratch or load from file using Java

Whether you’re creating a bitmap from scratch or loading one from an existing file, Aspose.Drawing for Java simplifies these common tasks, providing a seamless experience for bitmap creation and editing.

Create New Bitmap in Java

Creating a new image from scratch is pretty straightforward with the Aspose.Drawing Java API. The ensuing Java code example demonstrates how to create a new bitmap and draw an Arc on it:

  1. Create an instance of the Bitmap class.
  2. Initialize an object of the Graphics class from this bitmap.
  3. Define a Pen object with the desired parameters.
  4. Utilize the drawArc() method of the Graphics class object to draw an Arc.
// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
import com.aspose.drawing.*;
Bitmap bitmap = new Bitmap(1000, 800, com.aspose.drawing.imaging.Format32bppPArgb);
Graphics graphics = Graphics.fromImage(bitmap);
Pen pen = new Pen(Color.getBlue(), 2);
graphics.drawArc(pen, 0, 0, 700, 700, 0, 180);
bitmap.save("DrawArc.png");

Draw arc in bitmap in Java

Draw arc graphics on bitmap in Java

Load existing Image from File into Bitmap

Loading an existing image from a file and saving it back to disk using the Java API can be accomplished, as presented in the following Java code sample:

// For complete examples and data files, please go to https://github.com/aspose-drawing/Aspose.Drawing-for-JAVA
// Load the image:
Bitmap bitmap = new Bitmap(RunExamples.getDataDir() + "Images\\aspose_logo.png");
// Save the image:
bitmap.save(RunExamples.getDataDir() + "Images\\LoadSave_out.png");

Load and save image bitmap in Java

Load and save image bitmap in Java