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

Filling and drawing same GeneralPath do not match

XMLWordPrintable

    • 2d
    • generic, x86
    • generic, windows_2000

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]
      Service pack 4

      A DESCRIPTION OF THE PROBLEM :
      Sometimes the pixels touched by filling an area and then drawing the same area are not aligned. The filling seems to 'spill' pixels outside of the outline, and seems not to fill all pixels inside the outline.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The bug can be seen by running the attached program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I was expecting to see no visual distortion.
      ACTUAL -
      Blue pixels of the filling are seen outside the outline. White (background) pixels are left unfilled inside the outline.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.geom.*;
      import java.awt.image.*;
      import javax.swing.*;

      public class Spill
      {
          static public void main(String[] args)
          {
              /* Create an image */
              BufferedImage image = new BufferedImage(500,500,BufferedImage.TYPE_INT_RGB);
              Graphics2D graphics = image.createGraphics();
              graphics.setColor(Color.white);
              graphics.fillRect(0,0,image.getWidth(),image.getHeight());
              /* Make the shape */
              GeneralPath path = new GeneralPath();
              path.moveTo(-5.0f,-5.0f);
              path.lineTo(33.0f,-5.0f);
              path.lineTo(33.0f,19.0f);
              path.lineTo(-5.0f,19.0f);
              path.closePath();
              /* Render without error */
              graphics.translate(200.0,150.0);
              render(graphics,path);
              /* Render with error */
              graphics.translate(0.517747036277655,100.11394841313354);
              render(graphics,path);
              graphics.dispose();
              /* Show image */
              JFrame frame = new JFrame("Spill Test");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().add(new JLabel(new ImageIcon(image)));
              frame.pack();
              frame.show();
          }

          static private void render(Graphics2D graphics,GeneralPath path)
          {
              graphics.setColor(Color.blue);
              graphics.fill(path);
              graphics.setColor(Color.red);
              graphics.draw(path);
          }
      }

      ---------- END SOURCE ----------
      ###@###.### 10/21/04 10:28 GMT

            avu Alexey Ushakov
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: