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,
BufferedImage.TYPE_INT_ARGB);
....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):
http://194.255.21.180/img.png
http://194.255.21.180/img.jpg

Bigger versions can be seen here:
http://194.255.21.180/bigger.png
http://194.255.21.180/bigger.jpg

Firefox actually says the following when asked to display the JPEG:
<quote>
The image “http://194.255.21.180/img.jpg”; cannot be displayed, because
it contains errors.
</quote>
....but The Gimp has no problem displaying it.

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

Best,
Robert
.