This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Image to BufferedImage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image to BufferedImage" Watch "Image to BufferedImage" New topic
Author

Image to BufferedImage

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

my program uses BufferedImages. it stores them in an ArrayList. i am adding a feature and am going to use a utility class i found. it's method takes an Image and a Color as parameters, and it returns an Image. my program needs a BufferedImage. how can i change the Image into a BufferedImage?


SCJP
Visit my download page
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

First of all, check if the Image isn't already a BufferedImage (instanceof). If it isn't, you can create a new BufferedImage and draw on its Graphics object:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

thanks Rob
i know it isn't one because a cast didn't work....right?
the code you posted looks like just what i need though
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20078
    
  30

Randall Twede wrote:i know it isn't one because a cast didn't work....right?

If you got a ClassCastException, then it definitely isn't one
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Image to BufferedImage
 
It's not a secret anymore!