Example usage for java.awt Graphics2D scale

List of usage examples for java.awt Graphics2D scale

Introduction

In this page you can find the example usage for java.awt Graphics2D scale.

Prototype

public abstract void scale(double sx, double sy);

Source Link

Document

Concatenates the current Graphics2D Transform with a scaling transformation Subsequent rendering is resized according to the specified scaling factors relative to the previous scaling.

Usage

From source file:org.apache.fop.render.pcl.PCLDocumentHandler.java

private IFPainter createAllBitmapPainter() {
    double scale = gen.getMaximumBitmapResolution() / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
    Rectangle printArea = this.currentPageDefinition.getLogicalPageRect();
    int bitmapWidth = (int) Math.ceil(UnitConv.mpt2px(printArea.width, gen.getMaximumBitmapResolution()));
    int bitmapHeight = (int) Math.ceil(UnitConv.mpt2px(printArea.height, gen.getMaximumBitmapResolution()));
    this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
    Graphics2D graphics2D = this.currentImage.createGraphics();

    if (!PCLGenerator.isJAIAvailable()) {
        RenderingHints hints = new RenderingHints(null);
        //These hints don't seem to make a difference :-( Not seeing any dithering on Sun Java.
        hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
        graphics2D.addRenderingHints(hints);
    }/*from   www  .  java2 s.  c om*/

    //Ensure white page background
    graphics2D.setBackground(Color.WHITE);
    graphics2D.clearRect(0, 0, bitmapWidth, bitmapHeight);

    graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    graphics2D.scale(scale / 1000f, scale / 1000f);
    graphics2D.translate(-printArea.x, -printArea.y);

    return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}

From source file:org.apache.fop.render.pcl.PCLRenderer.java

/**
 * {@inheritDoc}/*from   w  ww. j a v a 2s  . co  m*/
 */
protected void renderText(final TextArea text) {
    renderInlineAreaBackAndBorders(text);

    String fontname = getInternalFontNameForArea(text);
    final int fontsize = text.getTraitAsInteger(Trait.FONT_SIZE);

    //Determine position
    int saveIP = currentIPPosition;
    final int rx = currentIPPosition + text.getBorderAndPaddingWidthStart();
    int bl = currentBPPosition + text.getOffset() + text.getBaselineOffset();

    try {

        final Color col = (Color) text.getTrait(Trait.COLOR);
        boolean pclFont = pclUtil.isAllTextAsBitmaps() ? false
                : HardcodedFonts.setFont(gen, fontname, fontsize, text.getText());
        if (pclFont) {
            //this.currentFill = col;
            if (col != null) {
                //useColor(ct);
                gen.setTransparencyMode(true, false);
                gen.selectGrayscale(col);
            }

            saveGraphicsState();
            graphicContext.translate(rx, bl);
            setCursorPos(0, 0);
            gen.setTransparencyMode(true, true);
            if (text.hasUnderline()) {
                gen.writeCommand("&d0D");
            }
            super.renderText(text); //Updates IPD and renders words and spaces
            if (text.hasUnderline()) {
                gen.writeCommand("&d@");
            }
            restoreGraphicsState();
        } else {
            //Use Java2D to paint different fonts via bitmap
            final Font font = getFontFromArea(text);
            final int baseline = text.getBaselineOffset();

            //for cursive fonts, so the text isn't clipped
            int extraWidth = font.getFontSize() / 3;
            final FontMetricsMapper mapper = (FontMetricsMapper) fontInfo.getMetricsFor(font.getFontName());
            int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000;
            final int additionalBPD = maxAscent - baseline;

            Graphics2DAdapter g2a = getGraphics2DAdapter();
            final Rectangle paintRect = new Rectangle(rx, currentBPPosition + text.getOffset() - additionalBPD,
                    text.getIPD() + extraWidth, text.getBPD() + additionalBPD);
            RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width,
                    paintRect.height, null);
            Map atts = new java.util.HashMap();
            atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP);
            atts.put(SRC_TRANSPARENCY, "true");
            rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts);

            Graphics2DImagePainter painter = new Graphics2DImagePainter() {

                public void paint(Graphics2D g2d, Rectangle2D area) {
                    g2d.setFont(mapper.getFont(font.getFontSize()));
                    g2d.translate(0, baseline + additionalBPD);
                    g2d.scale(1000, 1000);
                    g2d.setColor(col);
                    Java2DRenderer.renderText(text, g2d, font);
                    renderTextDecoration(g2d, mapper, fontsize, text, 0, 0);
                }

                public Dimension getImageSize() {
                    return paintRect.getSize();
                }

            };
            g2a.paintImage(painter, rc, paintRect.x, paintRect.y, paintRect.width, paintRect.height);
            currentIPPosition = saveIP + text.getAllocIPD();
        }

    } catch (IOException ioe) {
        handleIOTrouble(ioe);
    }
}

From source file:org.apache.fop.render.pcl.PCLRenderer.java

/**
 * Draws borders. Borders are drawn in-memory and painted as a bitmap.
 * @param borderRect the border rectangle
 * @param bpsBefore the border specification on the before side
 * @param bpsAfter the border specification on the after side
 * @param bpsStart the border specification on the start side
 * @param bpsEnd the border specification on the end side
 *//*from  w  w w.  java  2 s.  c  om*/
protected void drawQualityBorders(Rectangle2D.Float borderRect, final BorderProps bpsBefore,
        final BorderProps bpsAfter, final BorderProps bpsStart, final BorderProps bpsEnd) {
    Graphics2DAdapter g2a = getGraphics2DAdapter();
    final Rectangle.Float effBorderRect = new Rectangle2D.Float(0, 0, borderRect.width, borderRect.height);
    final Rectangle paintRect = new Rectangle(Math.round(borderRect.x * 1000f),
            Math.round(borderRect.y * 1000f), (int) Math.floor(borderRect.width * 1000f) + 1,
            (int) Math.floor(borderRect.height * 1000f) + 1);
    //Add one pixel wide safety margin around the paint area
    int pixelWidth = (int) Math.round(UnitConv.in2mpt(1) / userAgent.getTargetResolution());
    final int xoffset = Math.round(-effBorderRect.x * 1000f) + pixelWidth;
    final int yoffset = pixelWidth;
    paintRect.x += xoffset;
    paintRect.y += yoffset;
    paintRect.width += 2 * pixelWidth;
    paintRect.height += 2 * pixelWidth;

    RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width, paintRect.height,
            null);
    Map atts = new java.util.HashMap();
    atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP);
    atts.put(SRC_TRANSPARENCY, "true");
    rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts);

    Graphics2DImagePainter painter = new Graphics2DImagePainter() {

        public void paint(Graphics2D g2d, Rectangle2D area) {
            g2d.translate(xoffset, yoffset);
            g2d.scale(1000, 1000);
            float startx = effBorderRect.x;
            float starty = effBorderRect.y;
            float width = effBorderRect.width;
            float height = effBorderRect.height;
            boolean[] b = new boolean[] { (bpsBefore != null), (bpsEnd != null), (bpsAfter != null),
                    (bpsStart != null) };
            if (!b[0] && !b[1] && !b[2] && !b[3]) {
                return;
            }
            float[] bw = new float[] { (b[0] ? bpsBefore.width / 1000f : 0.0f),
                    (b[1] ? bpsEnd.width / 1000f : 0.0f), (b[2] ? bpsAfter.width / 1000f : 0.0f),
                    (b[3] ? bpsStart.width / 1000f : 0.0f) };
            float[] clipw = new float[] { BorderProps.getClippedWidth(bpsBefore) / 1000f,
                    BorderProps.getClippedWidth(bpsEnd) / 1000f, BorderProps.getClippedWidth(bpsAfter) / 1000f,
                    BorderProps.getClippedWidth(bpsStart) / 1000f };
            starty += clipw[0];
            height -= clipw[0];
            height -= clipw[2];
            startx += clipw[3];
            width -= clipw[3];
            width -= clipw[1];

            boolean[] slant = new boolean[] { (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3]) };
            if (bpsBefore != null) {
                //endTextObject();

                float sx1 = startx;
                float sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1);
                float ex1 = startx + width;
                float ex2 = (slant[1] ? ex1 - bw[1] + clipw[1] : ex1);
                float outery = starty - clipw[0];
                float clipy = outery + clipw[0];
                float innery = outery + bw[0];

                //saveGraphicsState();
                Graphics2D g = (Graphics2D) g2d.create();
                moveTo(sx1, clipy);
                float sx1a = sx1;
                float ex1a = ex1;
                if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
                    if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
                        sx1a -= clipw[3];
                    }
                    if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
                        ex1a += clipw[1];
                    }
                    lineTo(sx1a, outery);
                    lineTo(ex1a, outery);
                }
                lineTo(ex1, clipy);
                lineTo(ex2, innery);
                lineTo(sx2, innery);
                closePath();
                //clip();
                g.clip(currentPath);
                currentPath = null;
                Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, outery, ex1a - sx1a, innery - outery);
                Java2DRenderer.drawBorderLine(lineRect, true, true, bpsBefore.style, bpsBefore.color, g);
                //restoreGraphicsState();
            }
            if (bpsEnd != null) {
                //endTextObject();

                float sy1 = starty;
                float sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1);
                float ey1 = starty + height;
                float ey2 = (slant[2] ? ey1 - bw[2] + clipw[2] : ey1);
                float outerx = startx + width + clipw[1];
                float clipx = outerx - clipw[1];
                float innerx = outerx - bw[1];

                //saveGraphicsState();
                Graphics2D g = (Graphics2D) g2d.create();
                moveTo(clipx, sy1);
                float sy1a = sy1;
                float ey1a = ey1;
                if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
                    if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
                        sy1a -= clipw[0];
                    }
                    if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
                        ey1a += clipw[2];
                    }
                    lineTo(outerx, sy1a);
                    lineTo(outerx, ey1a);
                }
                lineTo(clipx, ey1);
                lineTo(innerx, ey2);
                lineTo(innerx, sy2);
                closePath();
                //clip();
                g.setClip(currentPath);
                currentPath = null;
                Rectangle2D.Float lineRect = new Rectangle2D.Float(innerx, sy1a, outerx - innerx, ey1a - sy1a);
                Java2DRenderer.drawBorderLine(lineRect, false, false, bpsEnd.style, bpsEnd.color, g);
                //restoreGraphicsState();
            }
            if (bpsAfter != null) {
                //endTextObject();

                float sx1 = startx;
                float sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1);
                float ex1 = startx + width;
                float ex2 = (slant[2] ? ex1 - bw[1] + clipw[1] : ex1);
                float outery = starty + height + clipw[2];
                float clipy = outery - clipw[2];
                float innery = outery - bw[2];

                //saveGraphicsState();
                Graphics2D g = (Graphics2D) g2d.create();
                moveTo(ex1, clipy);
                float sx1a = sx1;
                float ex1a = ex1;
                if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
                    if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
                        sx1a -= clipw[3];
                    }
                    if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) {
                        ex1a += clipw[1];
                    }
                    lineTo(ex1a, outery);
                    lineTo(sx1a, outery);
                }
                lineTo(sx1, clipy);
                lineTo(sx2, innery);
                lineTo(ex2, innery);
                closePath();
                //clip();
                g.setClip(currentPath);
                currentPath = null;
                Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, innery, ex1a - sx1a, outery - innery);
                Java2DRenderer.drawBorderLine(lineRect, true, false, bpsAfter.style, bpsAfter.color, g);
                //restoreGraphicsState();
            }
            if (bpsStart != null) {
                //endTextObject();

                float sy1 = starty;
                float sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1);
                float ey1 = sy1 + height;
                float ey2 = (slant[3] ? ey1 - bw[2] + clipw[2] : ey1);
                float outerx = startx - clipw[3];
                float clipx = outerx + clipw[3];
                float innerx = outerx + bw[3];

                //saveGraphicsState();
                Graphics2D g = (Graphics2D) g2d.create();
                moveTo(clipx, ey1);
                float sy1a = sy1;
                float ey1a = ey1;
                if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) {
                    if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) {
                        sy1a -= clipw[0];
                    }
                    if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) {
                        ey1a += clipw[2];
                    }
                    lineTo(outerx, ey1a);
                    lineTo(outerx, sy1a);
                }
                lineTo(clipx, sy1);
                lineTo(innerx, sy2);
                lineTo(innerx, ey2);
                closePath();
                //clip();
                g.setClip(currentPath);
                currentPath = null;
                Rectangle2D.Float lineRect = new Rectangle2D.Float(outerx, sy1a, innerx - outerx, ey1a - sy1a);
                Java2DRenderer.drawBorderLine(lineRect, false, false, bpsStart.style, bpsStart.color, g);
                //restoreGraphicsState();
            }
        }

        public Dimension getImageSize() {
            return paintRect.getSize();
        }

    };
    try {
        g2a.paintImage(painter, rc, paintRect.x - xoffset, paintRect.y, paintRect.width, paintRect.height);
    } catch (IOException ioe) {
        handleIOTrouble(ioe);
    }
}

From source file:org.apache.pdfbox.rendering.TilingPaint.java

/**
 * Returns the pattern image in parent stream coordinates.
 *///  w  w w .  jav a 2  s . c  o m
private BufferedImage getImage(PageDrawer drawer, PDTilingPattern pattern, PDColorSpace colorSpace,
        PDColor color, AffineTransform xform, Rectangle2D anchorRect) throws IOException {
    ColorSpace outputCS = ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm = new ComponentColorModel(outputCS, true, false, Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);

    float width = (float) Math.abs(anchorRect.getWidth());
    float height = (float) Math.abs(anchorRect.getHeight());

    // device scale transform (i.e. DPI) (see PDFBOX-1466.pdf)
    Matrix xformMatrix = new Matrix(xform);
    float xScale = Math.abs(xformMatrix.getScalingFactorX());
    float yScale = Math.abs(xformMatrix.getScalingFactorY());
    width *= xScale;
    height *= yScale;

    int rasterWidth = Math.max(1, ceiling(width));
    int rasterHeight = Math.max(1, ceiling(height));

    // create raster
    WritableRaster raster = cm.createCompatibleWritableRaster(rasterWidth, rasterHeight);
    BufferedImage image = new BufferedImage(cm, raster, false, null);

    Graphics2D graphics = image.createGraphics();

    // flip a -ve YStep around its own axis (see gs-bugzilla694385.pdf)
    if (pattern.getYStep() < 0) {
        graphics.translate(0, rasterHeight);
        graphics.scale(1, -1);
    }

    // flip a -ve XStep around its own axis
    if (pattern.getXStep() < 0) {
        graphics.translate(rasterWidth, 0);
        graphics.scale(-1, 1);
    }

    // device scale transform (i.e. DPI)
    graphics.scale(xScale, yScale);

    // apply only the scaling from the pattern transform, doing scaling here improves the
    // image quality and prevents large scale-down factors from creating huge tiling cells.
    Matrix newPatternMatrix;
    newPatternMatrix = Matrix.getScaleInstance(Math.abs(patternMatrix.getScalingFactorX()),
            Math.abs(patternMatrix.getScalingFactorY()));

    // move origin to (0,0)
    newPatternMatrix.concatenate(Matrix.getTranslateInstance(-pattern.getBBox().getLowerLeftX(),
            -pattern.getBBox().getLowerLeftY()));

    // render using PageDrawer
    drawer.drawTilingPattern(graphics, pattern, colorSpace, color, newPatternMatrix);
    graphics.dispose();

    return image;
}

From source file:org.apache.xmlgraphics.ps.ImageEncodingHelperTestCase.java

private BufferedImage prepareImage(final BufferedImage image) {
    final Graphics2D ig = image.createGraphics();
    ig.scale(.5, .5);
    ig.setPaint(new Color(128, 0, 0));
    ig.fillRect(0, 0, 100, 50);/*from   www . j  a v a2 s  .c om*/
    ig.setPaint(Color.orange);
    ig.fillRect(100, 0, 100, 50);
    ig.setPaint(Color.yellow);
    ig.fillRect(0, 50, 100, 50);
    ig.setPaint(Color.red);
    ig.fillRect(100, 50, 100, 50);
    ig.setPaint(new Color(255, 127, 127));
    ig.fillRect(0, 100, 100, 50);
    ig.setPaint(Color.black);
    ig.draw(new Rectangle2D.Double(0.5, 0.5, 199, 149));
    ig.dispose();
    return image;
}

From source file:org.dishevelled.piccolo.sprite.statemachine.AbstractStateMachineSprite.java

@Override
public final void paint(final PPaintContext paintContext) {
    if (currentAnimation != null) {
        Graphics2D g = paintContext.getGraphics();
        Image currentFrame = currentAnimation.getCurrentFrame();
        PBounds bounds = getBoundsReference();

        double w = currentFrame.getWidth(null);
        double h = currentFrame.getHeight(null);

        g.translate(bounds.getX(), bounds.getY());
        g.scale(bounds.getWidth() / w, bounds.getHeight() / h);
        g.drawImage(currentFrame, 0, 0, null);
        g.scale(w / bounds.getWidth(), h / bounds.getHeight());
        g.translate(-1 * bounds.getX(), -1 * bounds.getY());
    }//from  w  w  w  .  j ava  2  s.  co  m
}

From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java

public BufferedImage createTilePicture(int width) {

    Color[] colors = new Color[] { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW };

    double scale = width / sceneRectangle.getWidth();
    int height = (int) Math.round(sceneRectangle.getHeight() * scale);

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = image.createGraphics();
    graphics.scale(scale, scale);
    graphics.translate(-sceneRectangle.getX(), -sceneRectangle.getY());
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setPaint(Color.WHITE);
    graphics.fill(sceneRectangle);//from   w ww .ja  va2  s . co m
    graphics.setStroke(new BasicStroke(100F));
    graphics.setFont(new Font("Arial", Font.PLAIN, 800));

    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].brighter(), 100));
        graphics.fill(rect);
    }
    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].darker(), 100));
        graphics.draw(rect);
        graphics.setPaint(colors[i % colors.length].darker().darker());
        graphics.drawString("Tile " + (i + 1) + ": " + tileInfos[i].id, rect.x + 1200F, rect.y + 2200F);
    }
    return image;
}

From source file:org.jcurl.core.swing.RockLocationDisplayBase.java

/**
 * Draw one rock at it's wc position. Builds the coordinate transform and
 * calls {@link #paintRockRC(Graphics2D, boolean, int)}.
 * //  w  ww  . j a v  a 2 s .  c o m
 * @param g
 * @param rock
 * @param isDark
 * @param idx
 * @see RockPainter#paintRockRC(Graphics2D, boolean, int)
 */
protected void paintRockWC(final Graphics2D g, final Rock rock, final boolean isDark, final int idx) {
    final AffineTransform t = g.getTransform();
    g.translate(JCurlDisplay.SCALE * rock.getX(), JCurlDisplay.SCALE * rock.getY());
    g.rotate(Math.PI + rock.getZ());
    // make the right-handed coordinate system left handed again (for
    // un-flipped text display)
    g.scale(-1, 1);
    paintRockRC(g, isDark, idx);
    g.setTransform(t);
}

From source file:org.jcurl.demo.tactics.CurveShapeDemo.java

public static void main(String[] args) {
    log.info("Version: " + Version.find());
    final R1RNFunction c;
    {//w  w  w  .j  av a  2 s .  co  m
        final R1R1Function[] f = new R1R1Function[2];
        final double[] fx = { 200, 150 };
        final double[] fy = { 4, 4, 4, 4, 4 };
        f[0] = new Polynome(fx);
        f[1] = new Polynome(fy);
        c = new CurveFkt(f);
    }
    final CurveShapeDemo frame = new CurveShapeDemo(c);
    frame.setSize(500, 400);
    frame.setVisible(true);
    frame.setContentPane(new JPanel() {

        private static final long serialVersionUID = -3582299332757831635L;

        private final double[] sections = new double[10];

        final Stroke st = new BasicStroke(20, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0);

        public void paintComponent(Graphics g) {
            setBackground(new Color(255, 255, 255));
            super.paintComponent(g);
            setBackground(new Color(255, 255, 255));
            final Graphics2D g2 = (Graphics2D) g;
            g2.scale(0.75, 0.75);
            g2.setPaint(new Color(0, 0, 255));
            g2.setStroke(st);
            g2.drawLine(0, 0, 650, 500);
            g2.setPaint(new Color(255, 170, 0, 128));
            // FIXME g2.draw(CurveShape.approximate(frame.curve, CurveShape.sections(-1, 3, sections)));
        }
    });
}

From source file:org.jhotdraw.samples.svg.figures.SVGImage.java

@Override
public void draw(Graphics2D g) {
    AffineTransform t = g.getTransform();
    double scaleX = t.getScaleX();
    if (scaleX == 1.0) {
        g.drawImage(image, null, 0, 0);/*  w  w  w .  j a  v  a2  s  . c  om*/
        return;
    }
    g.scale(1 / scaleX, 1 / scaleX);
    BufferedImage scaledImage = scaledImages.get(scaleX);
    if (scaledImage == null) {
        int w = (int) (image.getWidth() * scaleX);
        int h = (int) (image.getHeight() * scaleX);
        scaledImage = new BufferedImage(w, h, image.getType());
        Graphics2D g2 = scaledImage.createGraphics();
        g2.drawImage(image, 0, 0, w, h, null);
        g2.dispose();
        scaledImages.put((Double) scaleX, scaledImage);
    }
    g.drawImage(scaledImage, null, 0, 0);
    g.setTransform(t);
}