/**
     * Draws as much of the specified area of the specified image as is
     * currently available, scaling it on the fly to fit inside the
     * specified area of the destination drawable surface. Transparent pixels 
     * do not affect whatever pixels are already there.
     * <p>
     * This method returns immediately in all cases, even if the
     * image area to be drawn has not yet been scaled, dithered, and converted
     * for the current output device.
     * If the current output representation is not yet complete then
     * <code>drawImage</code> returns <code>false</code>. As more of
     * the image becomes available, the process that loads the image notifies 
     * the specified image observer.
     * <p>
     * This method always uses the unscaled version of the image
     * to render the scaled rectangle and performs the required
     * scaling on the fly. It does not use a cached, scaled version
     * of the image for this operation. Scaling of the image from source
     * to destination is performed such that the first coordinate
     * of the source rectangle is mapped to the first coordinate of
     * the destination rectangle, and the second source coordinate is
     * mapped to the second destination coordinate. The subimage is
     * scaled and flipped as needed to preserve those mappings.
     * @param       img the specified image to be drawn. This method does
     *                  nothing if <code>img</code> is null.
     * @param       dx1 the <i>x</i> coordinate of the first corner of the
     *                    destination rectangle.
     * @param       dy1 the <i>y</i> coordinate of the first corner of the
     *                    destination rectangle.
     * @param       dx2 the <i>x</i> coordinate of the second corner of the
     *                    destination rectangle.
     * @param       dy2 the <i>y</i> coordinate of the second corner of the
     *                    destination rectangle.
     * @param       sx1 the <i>x</i> coordinate of the first corner of the
     *                    source rectangle.
     * @param       sy1 the <i>y</i> coordinate of the first corner of the
     *                    source rectangle.
     * @param       sx2 the <i>x</i> coordinate of the second corner of the
     *                    source rectangle.
     * @param       sy2 the <i>y</i> coordinate of the second corner of the
     *                    source rectangle.
     * @param       observer object to be notified as more of the image is
     *                    scaled and converted.
     * @return   <code>false</code> if the image pixels are still changing;
     *           <code>true</code> otherwise.
     * @see         java.awt.Image
     * @see         java.awt.image.ImageObserver
     * @see         java.awt.image.ImageObserver#imageUpdate(java.awt.Image, int, int, int, int, int)
     * @since       JDK1.1
     */
    public abstract boolean drawImage(Image img,
      int dx1, int dy1, int dx2, int dy2,
      int sx1, int sy1, int sx2, int sy2,
      ImageObserver observer);
方法报 
java.lang.ClassCastException: [S cannot be cast to [I
at java.awt.image.DirectColorModel.getRGB(DirectColorModel.java:697)
at sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(CustomComponent.java:127)
at sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:540)
at sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:521)
at sun.java2d.loops.Blit$GeneralXorBlit.Blit(Blit.java:244)
at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:927)
at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:550)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:73)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:998)
at sun.java2d.SunGraphics2D.copyImage(SunGraphics2D.java:2909)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3047)异常。。崩溃了。换成1.5 jdk就没问题有人知道原因么

解决方案 »

  1.   

    代码 平时运行没有异常 一旦我按下鼠标 就会出 无语了=。=Graphics2D g2d = (Graphics2D) g; AffineTransform origXform = g2d.getTransform();
    AffineTransform newXform = (AffineTransform) (origXform.clone());
    newXform.scale(1.0 * scale_factor / (1 << scale_shift),
       1.0 * scale_factor / (1 << scale_shift));
    newXform.translate(x, y);
    if ( (flag & FLAG_FLIPX) != 0) {
    newXform.scale( -1, 1);
    }
    if ( (flag & FLAG_FLIPY) != 0) {
    newXform.scale(1, -1);
    }
    newXform.concatenate(spt.trans);
    g2d.setTransform(newXform);
    try {
    g2d.drawImage(image, 0, 0, mod.w, mod.h, mod.x, mod.y,
      mod.x + mod.w,
      mod.y + mod.h, null);
    }
    catch (Exception ex) {
    //ex.printStackTrace();
    }
      

  2.   

    affinetransform这个类,1.6与1.5不同了
      

  3.   

    像一般运行期异常都是你自己程序本身的bug.!