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

REGRESSION:Graphics.drawImage based on a subimage draws at the wrong location

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b04
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      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)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      1.5.0 shows problem, 1.4.2_03 is ok on same machine

      A DESCRIPTION OF THE PROBLEM :
      Using drawImage to show a subimage extracted from the bottom right of a larger image causes the image to appear in the wrong location (appears to be offset as if the origin of the larger image were based at the destination x,y). My sample is scaled for twips, which seems to contribute to the problem. Without the scaling the result seems ok.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a sample image 100x100 pixels.Load and view it using the attached sample code. You should see the bottom right of your image.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      On JDK 1.4.2 the subimage is within the rectangle, this is the desired behaviour.
      ACTUAL -
      On JDK 1.5.0 the subimage is completely outside the rectangle.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // Test_SubImage.java

      import java.awt.*;
      import java.io.*;
      import javax.imageio.ImageIO;
      import javax.swing.*;

      public class Test_SubImage extends JComponent
      {
      public static void main(String[] args) throws Exception
      {
      System.out.println(System.getProperty("java.version"));
      JFrame f = new JFrame("Test SubImage");
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.getContentPane().add(new Test_SubImage());
      f.setBounds(50,50,400,400);
      f.setVisible(true);
      }

      public Test_SubImage() throws IOException
      {
      // test with a 100x100 pixel image
      m_Image = ImageIO.read(new File("C:\\Temp\\100x100.png"));
      }
      public void paint(Graphics g)
      {
      super.paint(g);
      Graphics2D g2 = (Graphics2D)g;
      g2.scale(0.05,0.05); // twips = 1/20 of a point

      // note dst is in twips, src is in pixels
      int dstX = 1640; // these values extracted from a debugging session
      int dstY = 1140;
      int srcX = 45;
      int srcY = 53;
      int srcW = 55;
      int srcH = 47;
      g2.drawImage(m_Image,
                                dstX,dstY,dstX+srcW*20,dstY+srcH*20,
                                srcX,srcY,srcX+srcW,srcY+srcH,null);
      g2.drawRect(dstX,dstY,srcW*20,srcH*20); // should coincide with drawn image
      }

      private Image m_Image;
      }

      // end of Test_SubImage.java
      ---------- END SOURCE ----------
      ###@###.### 11/4/04 23:22 GMT

        Attachments

          Activity

            People

            Assignee:
            flar Jim Graham
            Reporter:
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: