How can I save an Image file to disk in JPG or GIF format?
• If you have an Image and you want a JPG in a file, download James Weeks’s code from http://www.obrador.com/essentialjpeg/ • Sean Breslin also wrote a program that compresses a Java Image into a JPEG file. http://www.afu.com/jpeg.txt • If you just want to convert some file, a non-Java solution is to use the standard IJG ‘cjpeg’ utility. It supports GIF, PPM, BMP, PNG and Targa input files. • If you have an Image and you want a GIF or PPM in a file, download Jef Poskanzer’s abstract ImageEncoder class at http://www.acme.com/java/software/ • (Sect. 14) What causes this problem: $ appletviewer m.html Premature end of JPEG file sun.awt.image.Im…Exception: JPEG datastream contains no image at sun.awt.image. … .produceImage(JPEGImageDecoder.java:133) at sun.awt.image.Inpu…mageSource.doFetch( InputStreamImageSource.java:215) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:98) There’s a known bug in early releases of the JDK which can cause the above failure when reading a JPEG acro