Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Save transformed BufferedImage

 
Samuel Goldschmidt
Greenhorn
Posts: 15
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say it doesn't work, what doesn't? Are you seeing error messages or...?
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You rotate the graphics object only, not the image itself.

Moving to Swing / AWT.
 
Samuel Goldschmidt
Greenhorn
Posts: 15
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What doesn't work is: The saved image is not rotated.
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK I've got it now. Does someone know how to do it correctly?
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Samuel Goldschmidt
Greenhorn
Posts: 15
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic