title: Filling A Circle On The Outside, Inside Becomes Transparent
body: <p>Alright Stackoverflow, I need your help on this one with drawing.</p>
  
  <p>I am restricted to Graphics2D for this one and was wondering how I would be able to achieve an image that has two layers.</p>
  
  <p>First Layer - Color.white</p>
  
  <p>Second Layer - Color.red</p>
  
  <p>Now what I want to achieve is the ability to draw a circle that <strong><em>allows myself to see the first layer</em></strong> while the second layer is still red. <strong><em>Not simply draw a circle that is white.</em></strong></p>
  
  <p>Here is a picture of what I mean</p>
  
  <p><a href="https://i.stack.imgur.com/nhWjF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nhWjF.png" alt="enter image description here"></a></p>
  
  <p>I came across some previous code but it did not work, so I was hoping someone had the knowledge of Graphics2D to achieve this.</p>
  
  <p>Here is the code and I leave the rest to you.</p>
  
  <pre><code>BufferedImage img = new BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_RGBA);
  Graphics2D g = img.createGraphics();
  
  int ovalX = 50;
  int ovalY = 70;
  int ovalRadius = 20;
  
  /* Draw the grey rectangle */
  g.setColor(Color.GRAY);
  g.fillRect(0, 0, sizeX, sizeY);
  
  /* Enable Anti-Alias */
  g.setRenderingHint(RenderingHints.HINT_ANTIALIAS, RenderingHints.VALUE_ANTIALIAS_ON);
  
  /* Clear the circle away */
  g.setComposite(AlphaComposite.CLEAR, 1.0f);
  g.fillOval(ovalX - ovalRadius, ovalY - ovalRadius, 2 * ovalRadius, 2 * ovalRadius);
  
  g.dispose();
  </code></pre>