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

Graphics.drawImage() throws IllegalArgumentException

    XMLWordPrintable

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b12
    • CPU:
      sparc
    • OS:
      solaris_7

      Description



      Name: atR10191 Date: 11/22/2002


      method public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2,
                                               int dy2, int sx1, int sy1, int sx2,
                                               int sy2, Color bgcolor,
                                               ImageObserver observer)
      of class Graphics throws IllegalArgumentException
      See the example below.
      ============ Test171.java ==============================================
      import java.awt.*;
      import java.awt.image.MemoryImageSource;

      public class Test171 {

          public static void main(String argv[]) {
              Test171 test = new Test171();
              test.testGraphics2030_14();
              System.exit(0);
          }

          void testGraphics2030_14() {
              Frame frm = new Frame();
              frm.setVisible(true);
              Graphics g = frm.getGraphics();

              MemoryImageSource src2;

              frm.setSize(300, 300);
              int w = 50;
              int h = 50;
              int size = w * h;
              int pix[] = new int[size];

              int value = frm.getBackground().getRGB();
              for (int i = 0; i < size; i++) {
                  pix[i] = value;
              }

              src2 = new MemoryImageSource(w, h, pix, 0, w);
              src2.setAnimated(true);

              Image img = frm.createImage(src2);
          
              Rectangle rectDest = new Rectangle(Integer.MIN_VALUE, 0,
                                Integer.MAX_VALUE, Integer.MAX_VALUE);
              Rectangle rectSrc = new Rectangle(Integer.MIN_VALUE, 0,
                                Integer.MAX_VALUE, Integer.MAX_VALUE);
          
              g.drawImage(img, rectDest.x, rectDest.y,
                          rectDest.width, rectDest.height,
                          rectSrc.x, rectSrc.y, rectSrc.width,
                          rectSrc.height, Color.magenta, new Container());

             System.out.println("OKAY");

          }
      }
      ======== end of Test171.java ==========================================
      ======== output ==========================================
      Exception in thread "main" java.lang.IllegalArgumentException: Width (-1) and he
      ight (2147483647) cannot be <= 0
              at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Direct
      ColorModel.java:999)
              at sun.java2d.loops.BlitBg$General.BlitBg(BlitBg.java:136)
              at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:625)
              at sun.java2d.pipe.DrawImage.renderSurfaceData(DrawImage.java:346)
              at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:66)
              at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:733)
              at sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:2692)
              at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2821)
              at sun.awt.image.ImageRepresentation.drawToBufImage(ImageRepresentation.
      java:790)
              at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:740)
              at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:154)
              at sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:2692)
              at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2821)
              at Test171.testGraphics2030_14(Test171.java:41)
              at Test171.main(Test171.java:9)
      ======================================================================
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              flar Jim Graham
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: