Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image to BufferedImage

 
Randall Twede
Ranch Hand
Posts: 4409
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Randall Twede
Ranch Hand
Posts: 4409
3
Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic