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:
- Create an instance of the
Bitmapclass. - Initialize an object of the
Graphicsclass from this bitmap. - Define a
Penobject with the desired parameters. - Utilize the
drawArc()method of theGraphicsclass 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"); |
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"); |