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

Graphics.copyArea ignores translations for off-screen copies

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs
    • 2d
    • x86
    • windows_2000



      Name: jl125535 Date: 02/14/2003


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard
      Java HotSpot(TM) Client VM (build 1.4.0-

      Using the following VM in IE seems to work fine:

      Java(TM) Plug-in: Version 1.4.1_01
      Using JRE version 1.4.1_01 Java HotSpot(TM) Client VM

      But since this application is an applet, not all clients may be running the
      latest version,

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      The area copied seems to just be raw, rather than the area
      as it would have been translated. Haven't checks for
      scaling and other rotating.

      This happens in the plug-in in IE -- I haven't tested it in
      the raw SDK.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Code is attached
      2.
      3.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The copyArea should copy the area specified by the
      translated Graphics, but it seems to simply copy the area
      as specified in the copyArea call.

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package placeware.kb.browser.bb211;

      import java.applet.*;
      import java.awt.*;

      /**
       * This class will do a copyArea either with or
       * without an off-screen buffer.
       */

      public class CopyApplet extends Applet {
          Image buffer;
          Graphics bufGraphics;

          public CopyApplet() {}

          private boolean getBoolParameter (String name) {
      String value = getParameter(name);
      if (value == null) return false;
      if ("true".equals(value)) return true;
      else return false;
          }

          public void init () {
      setLayout(new BorderLayout());
      boolean buffer = getBoolParameter("buffer");
      add("Center", new CopyCanvas(100, 100, 10, 23, 35, -20, buffer));
          }

          // The Canvas that draws the funky stuff
          class CopyCanvas extends Canvas {
      int wCopy;
      int hCopy;
      int xtrans;
      int ytrans;
      int xdelta;
      int ydelta;
      boolean buffer;

      CopyCanvas (int wCopy, int hCopy,
      int xtrans, int ytrans,
      int xdelta, int ydelta,
      boolean buffer) {
      this.wCopy = wCopy;
      this.hCopy = hCopy;
      this.xtrans = xtrans;
      this.ytrans = ytrans;
      this.xdelta = xdelta;
      this.ydelta = ydelta;
      this.buffer = buffer;
      }

      public void paint (Graphics g) {
      if (buffer)
      paintB(g);
      else
      paintP(g);
      }

      // The real work
      public void paintP (Graphics g) {
      Rectangle b = getBounds();
      int xcenter = b.width/2;
      int ycenter = b.height/2;
      int radLimit2 = xcenter*xcenter+ycenter*ycenter;
      // Draw a bulls-eye
      for (int radius = 10; radius*radius < radLimit2; radius+=10)
      g.drawOval(xcenter-radius, ycenter-radius,
      2*radius, 2*radius);
      // translate, do a copy from the center, translate back
      g.translate(xtrans, ytrans);
      g.copyArea(xcenter-wCopy/2-xtrans, ycenter-hCopy/2-ytrans,
      wCopy, hCopy,
      xdelta, ydelta);
      g.translate(-xtrans, -ytrans);
      // Draw a red box from the source
      g.setColor(Color.red);
      g.drawRect(xcenter-wCopy/2, ycenter-hCopy/2,
      wCopy, hCopy);
      // Draw a green box around the destination
      g.setColor(Color.green);
      g.drawRect(xcenter-wCopy/2+xdelta, ycenter-hCopy/2+ydelta,
      wCopy, hCopy);
      if (buffer) {
      g.setColor(Color.magenta);
      g.drawRect(xcenter-wCopy/2-xtrans, ycenter-hCopy/2-ytrans,
      wCopy, hCopy);
      g.setColor(Color.blue);
      g.drawRect(xcenter-wCopy/2+xdelta-xtrans, ycenter-
      hCopy/2+ydelta-ytrans,
      wCopy, hCopy);
      }
      }

      // Use an off-screen buffer
      public void paintB (Graphics g) {
      Rectangle b = getBounds();
      Image buffer = createImage(b.width, b.height);
      System.err.println("buffer "+buffer);
      System.err.println("Paint "+g);
      Graphics bufG = buffer.getGraphics();
      System.err.println("bufG "+bufG);
      paintP(bufG);
      g.drawImage(buffer, 0, 0, null);
      }
          }
      }



      <!--
      $Id: //placeware/main/build/placeware.kb.browser/www/bb211/index.html.tmpl#1 $ -
      ->
      <html>
      <head>
      <title>Browser Bug 211</title>
      </head>
      <h1>Browser Bug 211</h1>

      <h3><a href="../browser-bugs.html#211"><tt>Graphics.copyArea()</tt>
       ignores transformations.</a></h3>
      [Java Plug-in: Version 1.4.0]
      <p>
      Each Applet on this page does a copyArea. The source
      of the copy is outlined in red, the destination is in green.
      The source is centered on the bulls-eye, and the
      green area should contain nothing but the middle of
      the bulls-eye.
      <p>
      This applet doesn't use an off-screen buffer. It works
      correctly everywhere. [Note however that damaging it with
      another window will cause redraws that it isn't ready to
      deal with.]
      <p>
      <applet code="placeware.kb.browser.bb211.CopyApplet"
      codebase="%codebase%"
      width=200 height=200
      >
      </applet>

      <br>
      This applet uses an off-screen buffer. In some browsers, the
      copyArea doesn't take into account the translation
      in effect in the off-screen Graphics. In that case, the
      destination of the copy will be the blue rectangle
      instead, and the source will be the magenta rectangle.
      <p>
      <applet code="placeware.kb.browser.bb211.CopyApplet"
      codebase="%codebase%"
      width=200 height=200
      >
      <param name="buffer" value="true">
      </applet>

      </html>


      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Keep track of the translations that have been applied,
      apply the inverse just before the copyArea call [so that on
      ALL browsers the current transformation will be the
      identity] then call copyArea, then re-apply the
      transformation.
      (Review ID: 144771)
      ======================================================================

            Unassigned Unassigned
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: