• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Save transformed BufferedImage

 
Greenhorn
Posts: 15
BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say it doesn't work, what doesn't? Are you seeing error messages or...?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What doesn't work is: The saved image is not rotated.
 
Rob Spoor
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK I've got it now. Does someone know how to do it correctly?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Samuel Goldschmidt
Greenhorn
Posts: 15
BSD
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic