Quality of AffineTransform.rotate

I want to draw a BufferedImage in an animation und rotate the original image each frame around an
increasing angle. Although I turned on Graphics2D-Antialias, I always end up with something like that -.-

http://img98.imageshack.us/img98/8231/pentagonrotatelqou8.jpg

Anyone know how to increase the rotation quality?

hehe, if anybody wanted to know how to spot a german in forums he got his anwser :slight_smile:

about rotation, I don’t know how to (or if you can) increase quality, somebody else will help you with that, but I know that rotation in Java2d is all done in software, at least on windows, nothing hardware accelerated. Very dissappointing for game devs using java2d.

Take a look at RenderingHints, it has a whole bunch of options to do that stuff:

http://java.sun.com/javase/6/docs/api/java/awt/RenderingHints.html#KEY_INTERPOLATION

Keith

PS: I’m pretty sure that the OGL pipeline does hardware rotation.

Austrian, not German :slight_smile:

@Kova: thx for that, I totally forgot that :slight_smile:
And is there any easier way to rotate and scale images with higher performance than
using JOGL? Maybe activating -Dsun.java2d.opengl? Or are there other APIs than let you
do 2-dimensional image transformations, that are easier to handle?

yes, java2d’s opengl backend also accalerates rotation.

greetings from austria (too), lg Clemens

opengl pipeline in my experience is very buggy… I mean it’s not Java, it’s ATI (and maybe nvidia?) drivers. Simple swing application didn’t work with my radeon x800, like jbuttons and half of stuff didn’t or were wrongly rendered. I don’t know how situation is on other platforms.

Could you please post your source image (unrotated) and then take a screenshot of what it looks like rotated? Also post the relevant source code. It’s hard to see what you’re doing from just this one image.

Chris

Yes ok, but with the KeyInterpolation set to Bileanar it works just fine :slight_smile:
The original image:

http://img293.imageshack.us/img293/5601/pentagonyellowod1.png

The rotated image without bilieaner interpolation:

http://img98.imageshack.us/img98/8231/pentagonrotatelqou8.jpg

The rotated image with bilieaner interpolation (and another background):

http://img87.imageshack.us/img87/3875/pentagonrotatehqir5.jpg

And the source code for transforming and drawing the image:

g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
		RenderingHints.VALUE_INTERPOLATION_BILINEAR);
AffineTransform aft = new AffineTransform();
aft.translate(90 - img.getWidth() / 2, 90 - img.getHeight() / 2);
aft.rotate(Math.toRadians(degree), img.getWidth() / 2,
		img.getHeight() / 2);
g2.drawImage(img, aft, this);

This is weird. Which JDK release are you running on? Which OS? Are you passing any system properties such as -Dsun.java2d.d3d=true or -Dsun.java2d.noddraw=true?

If you’re not using JDK 6, please try that release and see if you get different behavior. (We reimplemented our transform loops in JDK 6 so that they’re faster and more direct.)

Chris

I am using JDK 6 build 105 and only use “-Dsun.java2d.opengl=true” as VM arguments.
And I don’t quite get what is so weird about my samples? As far as I see everything works just fine…

Okay. This could be a bug in the OGL pipeline then. Which video board are you using, and which driver version? What kind of source image are you transforming (i.e. is it a BufferedImage or a VolatileImage)?

I assume that you don’t see this bug if you don’t pass -Dsun.java2d.opengl=true on the command line?

Huh? The whole point of this thread is that rotation is producing blocky (buggy) images; isn’t that why you started the thread in the first place? Your second screenshot is clearly showing a bug; it’s not what NEAREST_NEIGHBOR is supposed to look like. That’s what’s weird.

Chris

@campbell: uhm yes, I meant everything works just fine with Bilieanar interpolation^^

I’m not sure what’s a video board in german, so I’ll post a screenshot of the dxdiag and hope it will help…

http://img214.imageshack.us/img214/9461/dxdiagscreenshotsg7.jpg

but still, why not fully answer campbell’s question?

are you seeing the bug if you don’t use -Dsun.java2d.opengl=true ?
is img BufferedImage or VolatileImage?

sry I oversaw that…
I use BufferedImage and the “bug” occurs independent from the use of -Dsun.java2d.opengl=true