Hi Clifton,
You can use the following method to output the JPG image directly to a OutputStream:
OutputStream f = new FileOutputStream(filename);
OutputStream s = new BufferedOutputStream(f);
c.makeChart3().outJPG(s);
s.close();
f.close();
The above code will throw an I/O Exception if there is any error. By examining the exception, you may determine the cause of the problem.
One possible reason for the issue is because the Java VM does not have the JPEG codec "com.sun.image.codec.jpeg.JPEGCodec". This codec exists on Java 1.2 or above, but may or may not be available for Java VM not come from SUN/Oracle.
Since Java 1.4, there is another codec javax.imageio.ImageIO. If you only need to support Java 1.4 or above, you can use javax.imageio.ImageIO to create the JPEG file as well. The code is like:
javax.imageio.ImageIO.write((BufferedImage)c.makeImage(), "jpg", new File("myimage.jpg"));
Again, the above code can throw exceptions. By examining the exception, you may determine the cause of the problem.
Hope this can help.
Regards
Peter Kwan |