AffineTransform problems

hi to all,
My problem is that when I rotate my BufferedImage and then draw it on screen the image is cut and not fully drawn.

 
void update() {
    //...
        rads=0.068*3;
        if (initialRelativeYPos<23 && initialRelativeYPos%3==0){
            AffineTransform af = new AffineTransform();
            af.rotate(rads,width/2,height/2);
            AffineTransformOp op = new AffineTransformOp(af,AffineTransformOp.TYPE_BILINEAR);
            frames.set(currentFrame,(op.filter(frames.get(currentFrame) ,null)));
        }
    }

    public void draw(Graphics g) {
        if(IS_ALIVE){
            g.drawImage(frames.get(currentFrame),xPos,yPos,null);
        }
       //...

Original image:

http://img392.imageshack.us/img392/7782/bomb5oi.png

In Game image after Transformed:

http://img441.imageshack.us/img441/9334/cutbomb0cs.jpg

Does the destination image of the AffineTransformOp have the same dimensions as the source image? In that case the rotated version won’t even fit!

You could simply apply the affinetransform while drawing the image instead of first redrawing it onto another image. Set the transform of your graphics object (you can do that by first casting to Graphics2D) and reset it when you’re done drawing. That way your image won’t get cropped (and performance might be improved).

thanks for the help:
Here is the final code:


public void draw(Graphics g) {
        if(IS_ALIVE){
            Graphics2D g2 = (Graphics2D)g;
            rads=0.07;
            if (initialRelativeYPos<15){
                AffineTransform af = new AffineTransform();
                af.rotate(rads*initialRelativeYPos,width/2,height/2);
                AffineTransformOp op = new AffineTransformOp(af,AffineTransformOp.TYPE_BILINEAR);
                g2.drawImage(frames.get(currentFrame),op,xPos,yPos);
            }else{
                AffineTransform af = new AffineTransform();
                af.rotate(1.05,width/2,height/2);
                AffineTransformOp op = new AffineTransformOp(af,AffineTransformOp.TYPE_BILINEAR);
                g2.drawImage(frames.get(currentFrame),op,xPos,yPos);
            }
            g2.dispose();
        }