Rotating images

  • Thread starter Francois Lionet
  • Start date
F

Francois Lionet

Hello,

I have an Image, and I would like to get the same image, rotated.
I know I have to use the AffineTransformOp class to do the job. But the
problem is that this class only works with Graphics2D. I cannot find a way
to transform an image directly.
So, in fact I should : a) create a BufferedImage from my Image (which is not
simple, I have to create a buffered image, then get the graphics2d then draw
the image in it), b) create an compatible dest bufferedimage using
affinetransformop.createcompatibleDestImage, c) get a graphics2d on this
image, d) perform the rotation in the graphics2d. Pfwew. Long winded road
isn't it? Isn't there a better way of doing this?
If anyone has a direct method, please tell me!

Thanks, Francois
 
D

Daniel Pitts

Hello,

I have an Image, and I would like to get the same image, rotated.
I know I have to use the AffineTransformOp class to do the job. But the
problem is that this class only works with Graphics2D. I cannot find a way
to transform an image directly.
So, in fact I should : a) create a BufferedImage from my Image (which is not
simple, I have to create a buffered image, then get the graphics2d then draw
the image in it), b) create an compatible dest bufferedimage using
affinetransformop.createcompatibleDestImage, c) get a graphics2d on this
image, d) perform the rotation in the graphics2d. Pfwew. Long winded road
isn't it? Isn't there a better way of doing this?
If anyone has a direct method, please tell me!

Thanks, Francois

That doesn't sound to bad actually. You're question is a bit like.
"Is there a better way to paint a sun set. I need a canvas and some
paint to do it, but I can't find a way to get a sunset directly. So,
in fact I should: a) Buy a canvas and some paint at the art store. B)
Put the Canvas on my easel. c) spread my oils on my palette d) start
painting. "

Well, anyway, there is a more direct way.

Look at these three classes. You will need all three, if not more.
AffineTransformOp
BufferedImageFilter
and FilteredImageSource
 
W

Wojtek

Francois Lionet wrote :
Hello,

I have an Image, and I would like to get the same image, rotated.
I know I have to use the AffineTransformOp class to do the job. But the
problem is that this class only works with Graphics2D. I cannot find a way to
transform an image directly.
So, in fact I should : a) create a BufferedImage from my Image (which is not
simple, I have to create a buffered image, then get the graphics2d then draw
the image in it), b) create an compatible dest bufferedimage using
affinetransformop.createcompatibleDestImage, c) get a graphics2d on this
image, d) perform the rotation in the graphics2d. Pfwew. Long winded road
isn't it? Isn't there a better way of doing this?
If anyone has a direct method, please tell me!

Or you can use a tool which someone else has created:
http://www.nsftools.com/tips/JavaTips.htm#jpgimage
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top