开发者

drawRenderedImage(image, AffineTransform). How do I get the width and height of renderedImage

I'm drawing a transparent rendered image on top of a background image which is then displayed on a JPanel.

I need to get the bounds of the rendered image after it has been scaled and rotated. 开发者_StackOverflow社区 So that the next time I call repaint it can be with the clip of the rendered image.

Any ideas? thanks for your help.

@Override public void paintComponent(java.awt.Graphics g)
{
    if(g != null)
    {
        g.drawImage(backgroundImage, 0, 0, getWidth(), getHeight(), null);
        Graphics2D g2 = (Graphics2D)g.create();
        double cx = sprite.getWidth()  / 2.0;
        double cy = sprite.getHeight() / 2.0;
        AffineTransform at = AffineTransform.getTranslateInstance(xPos, yPos);
        at.concatenate(AffineTransform.getScaleInstance(scale, scale));
        at.rotate(theta, cx, cy);
        g2.drawRenderedImage(sprite, at);

        //get width and height of rendered image here?

        g2.dispose();
     }


Something like

Rectangle resizedBounds = at.createTransformedShape(sprite.getBounds()).getBounds();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜