z  -
z -

Reputation: 7178

BufferedImage Rotation

What is the best way of rotating a bufferedimage about its center where the gradient is 1 degree?

I know there is AffineTransform, but that causes shearing and weird stretching or black spots that should be blank.

edit The sizes of images I am dealing with are icon sizes, so typically 24x24 up to 48x48 pixels

Upvotes: 0

Views: 1380

Answers (4)

Sandeep Datta
Sandeep Datta

Reputation: 29345

The quality of rotation for such a small angle will vary greatly with the size of the image. How big is your image?

[After the OP edited the question to indicate the size of the image]

IMO the image is too small for any meaningful rotation other than in multiples of 90 degrees (assuming its a square). I am afraid this needs to be done manually by a graphic designer to get the best possible quality.

[Another alternative]

Keep a high res version of the image around. Apply all your transformations to this image and then scale down to obtain an icon.

Upvotes: 3

Zarkonnen
Zarkonnen

Reputation: 22478

As a quick and dirty fix, have you considered the following method:

  • scale up the image by a factor of eg 8, by drawing it onto a new bufferedimage
  • rotate the image, by drawing it transformed by an affinetransform
  • scale it back down again, by drawing it onto yet another new bufferedimage

Any low-level artefacts should vanish during the scale-down. This isn't perhaps the fastest option, but it may well do what you want with a minimum of fuss - and more complex solutions may likely boil down to doing the same thing behind the scenes.

Upvotes: 1

jedierikb
jedierikb

Reputation: 13109

Here are some links which explain how you might want to proceed when applying transforms to icons.

Java 2D Trickery: Antialiased Image Transforms http://weblogs.java.net/blog/campbell/archive/2007/03/java_2d_tricker_1.html

Sub pixel sampling of Raster or DataBuffer in BufferedImage. http://forums.java.net/jive/thread.jspa?messageID=204921&tstart=0

Upvotes: 0

jedierikb
jedierikb

Reputation: 13109

Have you tried setting the anti-aliasing of your graphics context?

g2d.setRenderingHint(
    RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON
);

Upvotes: 2

Related Questions