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
.



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. ...
    (microsoft.public.publisher)
  • 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 ...
    (rec.photo.digital)
  • 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 ...
    (rec.photo.digital)
  • 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. ...
    (rec.photo.digital)
  • Re: Which Version of Photoshop?
    ... such as jpeg or tiff. ... He specified that he uses the .tif format. ... It's still Painter file but not a file saved in Painter's ...
    (rec.photo.digital)