Results 1 to 5 of 5
Thread: Writing an Image to a File
- 04-30-2010, 08:10 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
Writing an Image to a File
Hello,
I have created an image using the Graphics2D class. I would like to be able to take the image I created and save it into a file. I have some familiarity with Input and Output streams but I can't seem to figure out make take the image and output it into a file. Any help or suggestions that are given will be greatly appreciated.
If the code of my image is necessary let me know and I will post it.
Thank You
- 04-30-2010, 08:39 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
I suspect you have a drawing on screen and you want to convert it to an Image. Have a look at the SwingUtilities.convertPointToScreen( ... ) method and the Robot.createScreenCapture( ... ) method. Both can create an Image for you. Then have a look at the ImageIO class, it can save an Image for you.
kind regards,
Jos
- 04-30-2010, 08:47 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Using a Robot to capture the image is "relatively" slow. Its faster to paint the image onto a BufferedImage. The Screen Image class attempts to simplify this process.
- 04-30-2010, 09:20 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
Nice class (I always lurk at that site and your replies ;-) but reading from video memory, although way beyond or below Java's capabilities, is not necessarily slower than reading from other memory; it depends on the hardware. (I happen to know something about that). Thanks for sharing all your knowledge w.r.t. Java's Swing framework etc.
kind regards,
Jos
- 04-30-2010, 09:32 PM #5
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
When I tested it on my machine it was much slower, so I created all the overloaded methods to try and get the best performance. I hope its not the opposite behaviour on all other machines :)but reading from video memory, although way beyond or below Java's capabilities, is not necessarily slower than reading from other memory; it depends on the hardware
Similar Threads
-
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
Writing text into an image and save it
By elcapi in forum Java 2DReplies: 6Last Post: 09-18-2009, 05:47 PM -
error encountered when writing image file
By angelinehelena in forum Advanced JavaReplies: 1Last Post: 02-10-2009, 10:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks