I am drawing a graphical representation of information my simulation is generating. I have the graph displaying but the problem i am running into is to be able to save it as a .png. When it saves the png, the file is all black, so it's not saving my graph but creating some blank png file. The problem is I am having difficulty figuring out how to cast to a BufferedImage or a RenderedImage all of my attempts in eclipse throw errors and when I get it to compile, it works as how I described above. Any thoughts or suggestions? I have been stuck on this for a couple of weeks and either it is an obvious fix or I am not able to save it as png. But from the research i have conducted, it is possible to save a java 2d graphics img as a png file, I don't know what I am missing? A fresh pair of eyes would be greatly and immensely appreciated! Thank you in advance, I appreciate any and all advice or comments regarding this.

Thank you for the links, I was able to use both to get it work but in the end used Screen Image because of image aesthetics. Thank you guys so much, problem solved!
–
theoreticalyieldNov 20 '11 at 21:37

It appears that you never actually paint to the BufferedImage in your saveGraph(..) routine.

After you create your BufferedImage and retrieve the Graphics object for that image, call the paintComponent method of your main class passing that graphics context. You also are create two GraphDisplay objects but never use either one.

I implemented what you suggested but it still renders a black .png file, any suggestions? Thanks!
–
theoreticalyieldNov 22 '11 at 2:53

This is the approach that I initially was trying to implement however, when I use TYPE_INT_RGB I get an all black .png and when I use TYPE_INT_ARGB I get a grey png file with nothing rendered to it. Must be something I am missing... Thanks again!
–
theoreticalyieldNov 22 '11 at 14:33