i have a class that draws a shape from a png image, so that i can use the shape to draw the border of custom buttons that i need for my project. here's the code for the class to draw the shape of an image:
public class CreateShapeClass {
public static Area createArea(BufferedImage image, int maxTransparency) {
Area area = new Area();
Rectangle rectangle = new Rectangle();
for (int x = 0; x < image.getWidth(); x++) {
for (int y = 0; y < image.getHeight(); y++) {
int rgb = image.getRGB(x, y);
rgb = rgb >>> 24;
if (rgb >= maxTransparency) {
rectangle.setBounds(x, y, 1, 1);
area.add(new Area(rectangle));
}
}
}
return area;
}
}
however, this takes a very long time to process, and I thought that by pre-drawing the shapes in my main application and then storing them into an array and passing to other classes, it will reduce the rendering time. however, the time taken for the paintBorder() method to draw out the border of the button takes a pretty long time too (although shorter than the time required to draw the shape), because the shape generated by the class above is filled and not empty. I've tried to draw shapes using java2d, for example, Ellipse2D, and the rendering of the button only takes a very short time. anyone experienced in this field can teach me how do i generate a shape that is the border of a BufferedImage? i use the class above to create the shape from PNG image with a transparent background.