Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8286964

Antialiasing ON in BufferedImage not work

    XMLWordPrintable

Details

    • 2d
    • x86_64
    • windows_10

    Description

      A DESCRIPTION OF THE PROBLEM :
      drawText(), draw() polygons, drawLine() to BufferedImage are not Antialiased on all last OpenJDK and OracleJDK on Windows 10 x64. Last test on OpenJDK 19-ea+22-1598.

      Compare direct and buffered 2D are in "Steps to Reproduce".

      Working on OracleJRE 8u333.
      Working on OpenJDK 8u41+b04-windows-i586-jan-2020 ( 1.8.0_41 )
      Not working on OpenJDK 19-ea+22-1598.
      Not working on OracleJDK 18.0.1.1+2-6


      REGRESSION : Last worked in version 8u333

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.awt.BasicStroke;
      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.RenderingHints;
      import java.awt.image.BufferedImage;

      import javax.swing.JFrame;
      import javax.swing.JPanel;

      public class Test {
          public static void main(String[] args){
              doDirect();
              doBuffered();
          }
          public static void doBuffered(){
              JFrame frame = new JFrame();
              frame.setTitle("BufferedImage drawn with antialiasing on");
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JPanel canvas = new JPanel(){
                  @Override
                  protected void paintComponent(Graphics g){
                      BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
                      Graphics2D ig2d = image.createGraphics();
                      ig2d.setColor(Color.BLACK);
                      ig2d.setStroke(new BasicStroke(3));
                      ig2d.setRenderingHint(
                              RenderingHints.KEY_ANTIALIASING,
                              RenderingHints.VALUE_ANTIALIAS_ON);
                      ig2d.drawLine(10, 10, 70, 90);
                      
                      Graphics2D g2d = (Graphics2D)g;
                      g2d.drawImage(image, 0, 0, null);
                  }
              };
              canvas.setPreferredSize(new Dimension(100, 100));
              frame.getContentPane().add(canvas, BorderLayout.CENTER);
              frame.setEnabled(true);
              frame.pack();
              frame.setVisible(true);
          }
          public static void doDirect(){
              JFrame frame = new JFrame();
              frame.setTitle("Directly drawn with antialiasing on");
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              JPanel canvas = new JPanel(){
                  @Override
                  protected void paintComponent(Graphics g){
                      Graphics2D g2d = (Graphics2D)g;
                      g2d.setColor(Color.BLACK);
                      g2d.setStroke(new BasicStroke(3));
                      g2d.setRenderingHint(
                              RenderingHints.KEY_ANTIALIASING,
                              RenderingHints.VALUE_ANTIALIAS_ON);
                      g2d.drawLine(10, 10, 70, 90);
                  }
              };
              canvas.setPreferredSize(new Dimension(100, 100));
              frame.getContentPane().add(canvas, BorderLayout.CENTER);
              frame.setEnabled(true);
              frame.pack();
              frame.setVisible(true);
          }
      }


      FREQUENCY : always


      Attachments

        1. Capture1.PNG
          Capture1.PNG
          19 kB
        2. Capture2.PNG
          Capture2.PNG
          11 kB
        3. Test.java
          3 kB

        Activity

          People

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: