This tutorial compiles the information to draw circle in Java. It contains the system setup information, stepwise process details, and a running sample code to create a circle drawer in Java. Furthermore, you can enhance or improvise the drawing of a circle by changing different properties to meet your requirements.
Steps to Draw Circle in Java
- Prepare the system to work with Aspose.Drawing for drawing circles
- Initiate a Bitmap class object while specifying the image size and pixel format
- Create a Graphics class instance using the Bitmap class object
- Call the drawEllipse method while defining a Pen class object and size of the circle
- Export the output image
These steps can be followed to draw a perfect circle in Java. Simply start the drawing by initiating a bitmap of your required height and width. Then define the width of the line and color of the outline and finally write the output circle drawing as an image.
Code for Circle Drawing in Java
// Create bitmap and load into graphics object | |
com.aspose.drawing.Bitmap BitmapImage = new com.aspose.drawing.Bitmap(512, 512, | |
com.aspose.drawing.imaging.PixelFormat.Format32bppPArgb); | |
com.aspose.drawing.Graphics GraphicsFromImage = | |
com.aspose.drawing.Graphics.fromImage(BitmapImage); | |
// Create a pen tool and draw circle | |
com.aspose.drawing.Pen PenTool = new com.aspose.drawing.Pen(com.aspose.drawing.Color.getGreen(), 3); | |
GraphicsFromImage.drawEllipse(PenTool, 20, 20, 400, 400); | |
// Save output png file | |
BitmapImage.save("Circle.png"); |
The basic code snippet showcases the simplest version to make a circle in Java. Where a lot of variations are easily possible as you can change the size of the output image, creating an image from scratch or using an existing one. Similarly, the outline color, fill color, line size, etc. can be changed by setting the relevant properties.
This topic has explained circle drawing in Java. However, if you want to draw Pentagon, then you can take a look at the article on Draw Pentagon in Java.