my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Save transformed BufferedImage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Save transformed BufferedImage" Watch "Save transformed BufferedImage" New topic
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: 3274
    
    5

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: 19655
    
  18

You rotate the graphics object only, not the image itself.

Moving to Swing / AWT.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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: 19655
    
  18

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: 19655
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save transformed BufferedImage
 
Similar Threads
Problem with creating a BufferedImage and save it as bmp file
Using readObject() for BufferedImage
ImageIO.write - TIF and BMP - Zero bytes
Screen Capture allows the same picture
Sometimes applet doesn't draw some JPanel elements