• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Image "snapshot" question

 
Eric Chang
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I was to have a frame with many different Swing components in it (panels, labels, etc.)...is there a way to take a "snapshot" of the contents of the frame? Would it just be a case of when creating and adding each component, to also "draw" it to a BufferedImage?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
post #5 at this link seems to work OK

http://forum.java.sun.com/thread.jspa?threadID=580960&tstart=0
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a BufferedImage the size of the component, get a reference to its graphics context with createGraphics and pass this to the components paint method. It will draw itself into your new BufferedImage. Save the image to file with ImageIO.write.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!