| Author |
Save transformed BufferedImage
|
Samuel Goldschmidt
Greenhorn
Joined: Jun 14, 2009
Posts: 15
|
|
Hello community,
I want to load an image from the hard disk, then rotate it by 90° and then save the rotated version to another file. However, the following doesn't work:
Could you tell me what I am doing wrong and/or show me how it's done properly?
Regards,
Sam
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
|
When you say it doesn't work, what doesn't? Are you seeing error messages or...?
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
You rotate the graphics object only, not the image itself.
Moving to Swing / AWT.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Samuel Goldschmidt
Greenhorn
Joined: Jun 14, 2009
Posts: 15
|
|
|
What doesn't work is: The saved image is not rotated.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Because you're not rotating the image. Rotating the Graphics object does not rotate the image. Perhaps you should check out the Java2D Tutorial
|
 |
Samuel Goldschmidt
Greenhorn
Joined: Jun 14, 2009
Posts: 15
|
|
|
OK I've got it now. Does someone know how to do it correctly?
|
 |
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
|
|
|
|
 |
Samuel Goldschmidt
Greenhorn
Joined: Jun 14, 2009
Posts: 15
|
|
Well, thanks a lot, Craig! This worked! (Save for the src.getType(), but I just put in src.TYPE_INT_RGB)
g2.drawImage(src, ...) is really cool. I think I didn't know what to do because I didn't know what g2.drawImage(...) does. I used it before to draw BufferedImages on JPanels, but actually it's a function which copies image data to specific memory locations, isn't it?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
It depends on the Graphics object. For BufferedImage, it's an in-memory object. For components it can be regarded as a representation of the screen. When printing it can be regarded as a representation of a paper sheet.
|
 |
 |
|
|
subject: Save transformed BufferedImage
|
|
|