public Rectangle2D drawImage(PDFImage image) {
        AffineTransform at = new AffineTransform(1f / image.getWidth(), 0,
                0, -1f / image.getHeight(),
                0, 1);

        BufferedImage bi = image.getImage();
        if (bi == null) {
            // maybe it was an unsupported format, or something.
            // Nothing to draw, anyway!
            return new Rectangle2D.Double();
        }

        if (image.isImageMask()) {
            bi = getMaskedImage(bi);
        }

        /*
        javax.swing.JFrame frame = new javax.swing.JFrame("Original Image");
        frame.getContentPane().add(new javax.swing.JLabel(new javax.swing.ImageIcon(bi)));
        frame.pack();
        frame.show();
         */

        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
        if (!g.drawImage(bi, at, null)) {
            System.out.println("Image not completed!");
        }

        // get the total transform that was executed
        AffineTransform bt = new AffineTransform(g.getTransform());
        bt.concatenate(at);

        double minx = bi.getMinX();
        double miny = bi.getMinY();

        double[] points = new double[]{
            minx, miny, minx + bi.getWidth(), miny + bi.getHeight()
        };
        bt.transform(points, 0, points, 0, 2);

        return new Rectangle2D.Double(points[0], points[1],
                points[2] - points[0],
                points[3] - points[1]);

    }