This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why use a Buffered Image insead of an Image?  RSS feed

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking at the code here which let's you drag an image around the screen:
http://www.java2s.com/Code/Java/2D-Graphics-GUI/Imagewithmousedragandmoveevent.htm

Why did they do this:

Why did they have to go through the trouble of making a bufferedimage and then converting it to a graphic and then drawing the image? Why not just instantiate a new Graphic2D object and use that to draw the image?
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like something which would sit better on our GUIs forum. Moving discussion.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ofcourse I don't know why the author of that code wrote it that way; maybe that person thought that loading a GIF image with getToolkit().getImage(...) is the easiest way to do it. But it's just as easy with ImageIO, and it will directly return a BufferedImage:

No need to draw the image on a new BufferedImage.
 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, when would you use a BufferedImage instead of just an Image?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anywhere you require to use API that is present in BufferedImage but not in Image.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!