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

drawOval to offscreen image results in lumpy circles

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs
    • None
    • 2d
    • x86, sparc
    • solaris_2.6, windows_nt

      The following code uses drawOval with increasing width/heights to draw circles. The first line of circles is drawn directly on screen, with the remaining lines created from an offscreen image. As you can see the first line of circles look quite good, while the remaining lines of circles look rather lumpy and distorted, especially for the smaller sizes. I ran this against 1.2fcs, build M.

      import java.awt.*;
      import java.awt.event.*;

      public class OvalTest2 extends Container {
          public static final int TOTAL = 30;
          public static final int MAX_RAD = 24;

          public Dimension getPreferredSize() {
              return new Dimension(300, 100);
          }

          public Dimension getMinimumSize() {
              return getPreferredSize();
          }

          public Dimension getMaximumSize() {
              return getPreferredSize();
          }

          public void paint(Graphics g) {
      Dimension size = getSize();
              int maxY = size.height / TOTAL * TOTAL;

      // Create an image for all rows, but the first.
        Image i = createImage(size.width, TOTAL);

              doDraw(i.getGraphics(), size.width);

      // Draw the first row.
      g.setColor(Color.white);
      g.fillRect(0, 0, size.width, size.height);
              doDraw(g, size.width);

      // Draw the remaining rows using the offscreen image.
      for (int counter = maxY; counter >= TOTAL; counter -= TOTAL) {
      g.drawImage(i, 0, counter, null);
      }
          }

          public void doDraw(Graphics g, int width) {
      g.setColor(Color.white);
      g.fillRect(0, 0, width, 30);
              g.setFont(g.getFont());
      g.setColor(Color.black);
              int rad = 5;
      for (int counter = 0; counter < width; counter += rad + 4) {
                  if (rad++ == MAX_RAD) {
                      rad = 6;
                  }
      g.drawOval(counter, 0, rad, rad);
      }
          }

          public static void main(String[] args) {
              Frame f = new Frame("Oval test");
      final OvalTest2 ov = new OvalTest2();
      f.add(ov);
      f.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent we) {
      System.exit(0);
      }
      });
              f.pack();
              f.show();
          }
      }

            flar Jim Graham
            svioletsunw Scott Violet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: