ImageIO problems encoding jpeg

Hi group

I have some code that saves an image to a file using ImageIO. And it
works for all formats except jpeg. A scaled down version follows:

public void write(String filename) throws IOException {
int idx = filename.lastIndexOf('.');
if (idx >= 0) {
File file = new File(filename);
String format = filename.substring(idx + 1).toLowerCase();
ImageIO.write(image, format, file);

The image has been instanciated using:
image = new BufferedImage(w > 0 ? w : 1, h > 0 ? h : 1,
....where 'w' is the width and 'h' is the height.

And given "img.png" I get a very nice PNG image. But "img.jpg" gives a
weird result.

The two images can be seen here (they are quite small):

Bigger versions can be seen here:

Firefox actually says the following when asked to display the JPEG:
The image “”; cannot be displayed, because
it contains errors.
....but The Gimp has no problem displaying it.

Has anybody seen this ?
Or do you know what I am doing wrong ?


Relevant Pages

  • Re: Best export format for commercial print from Publisher
    ... What's the difference between PNG, TIFF, BMP, and JPEG? ... PDF's as a practical matter for most purposes cap out at 1200 dpi, ... resolution imaging for printing presses 2400 is standard. ... PDF is just a container format essentially. ...
  • Re: What makes a mac better?
    ... Unfortunately, JPEG wasn't a viable option back in 1992, as you've ... what specific format was being recommended for use back in 1992. ... and that this data file has been irrecoverably lost, ... ....but then ran away from that JPEG recommendation like a scalded cat ...
  • Re: What makes a mac better?
    ... Call your JPEG encoded picture ... standard' format at the time of its creation. ... old Egyptian hieroglyphs and Cuneiform have been lost in time. ... the archived NASA data, contact NASA and recover the data, and provide ...
  • Re: lossless format
    ... each time you copy a jpeg it degenerates in quality. ... Mass storeage for backup has chnaged to a format I do not really favor ... You defend WMA and you are Happy with it, I never accused you have MP3, ... WAV is far more supported with NON WINDOWS BASED PLAYERS than WMA, ...
  • Re: Best format question
    ... I discovered that this format is prone to progressive quality loss over ... my camera only produces JPGs. ... tool and then once you make any changes saving as tiff would be fine, ... open them make a global change and resave as JPEG. ...