*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 4340
    
    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: 19654
    
  18

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
How To Ask Questions How To Answer Questions
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    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: 19654
    
  18

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
 
jQuery in Action, 2nd edition
 
subject: Image to BufferedImage
 
Similar Threads
DPI improvement
How to create an image from JPanel contents?
Only getting a PropertyChangeEvent at the end of SwingWorker
Loading JPG with JAI
display image from bytearray