Results 1 to 5 of 5
  1. #1
    Sadis5815 is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Sadis5815 View Post
    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
    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

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    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.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,445
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by camickr View Post
    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.
    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

  5. #5
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    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
    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 :)

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  2. Writing text into an image and save it
    By elcapi in forum Java 2D
    Replies: 6
    Last Post: 09-18-2009, 05:47 PM
  3. error encountered when writing image file
    By angelinehelena in forum Advanced Java
    Replies: 1
    Last Post: 02-10-2009, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •