title: Java Graphics2D drawImage() and clip(): how to apply antialiasing?
body: <p>The <code>BufferedImage</code> drawn by the <code>drawImage</code> and <code>clip</code> method of Java Graphics2D have jagged edges, how to apply antialiasing?</p>
  
  <p><a href="https://i.stack.imgur.com/3PMMu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3PMMu.png" alt="enter image description here"></a></p>
  
  <p>The code:</p>
  
  <pre><code>BufferedImage img = ImageIO.read(new File("D:\\Pictures\\U\\U\\3306231465660486.jpg"));
  
  JFrame frame = new JFrame();
  frame.add(new JPanel() {
      @Override
      protected void paintComponent(Graphics g) {
          Graphics2D g2d = (Graphics2D) g;
          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  
          g2d.setColor(Color.RED);
          g2d.drawLine(10, 10, 300, 100);
  
  
          g2d.translate(50, 200);
          g2d.rotate(Math.toRadians(30), getWidth() / 2.0, getHeight() / 2.0);
          g2d.drawImage(img, 0, 0, this);
          g2d.clip(new Rectangle(-110, 110, 80, 110));
          g2d.fill(new Rectangle(-100, 100, 100, 100));
      }
  });
  
  frame.setSize(600, 600);
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
  </code></pre>