开发者

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

开发者 https://www.devze.com 2023-01-06 01:05 出处:网络
I\'m drawing a transparent rendered image on top of a background image which is then displayed on a JPanel.

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

精彩评论

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