I want to create a “ring” in a BufferedImage with a transparent background. I can draw the circle with a transparent background like this:
BufferedImage bi = new BufferedImage(d, d, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(c);
g.fillOval(0, 0, d, d);
But now I want to draw a smaller transparent circle in the middle of it to make a ring (so when I draw this image over another image, the pixels around and inside the ring are not drawn). I want to use a Graphics object to do this so I can use antialiasing.
Is this possible? If it isn’t, what it the best way to tackle this problem?
Create a circular shape, then subtract another circular shape from that, set it as the clip & you might end up with something along the lines needed. To hide the rough edges of the clip, draw a 2px wide stroke of the shape.