// exceptions due to stream closings. If it gets an exception
// it nulls out the stream and just ignores any future calls.
ostream = new OutputStreamWrapper(ostream);
if (ostream == null) {
throw new TranscoderException(
Messages.formatMessage("jpeg.badoutput", null));
}
try {
float quality;
if (hints.containsKey(KEY_QUALITY)) {
quality = ((Float)hints.get(KEY_QUALITY)).floatValue();
} else {
TranscoderException te;
te = new TranscoderException
(Messages.formatMessage("jpeg.unspecifiedQuality", null));
handler.error(te);
quality = .75f;
}
JPEGImageEncoder jpegEncoder;
JPEGEncodeParam params;
jpegEncoder = JPEGCodec.createJPEGEncoder(ostream);
params = JPEGCodec.getDefaultJPEGEncodeParam(img);
params.setQuality(quality, true);
float PixSzMM = userAgent.getPixelUnitToMillimeter();
int PixSzInch = (int)(25.4/PixSzMM+0.5);
params.setDensityUnit(JPEGEncodeParam.DENSITY_UNIT_DOTS_INCH);
params.setXDensity(PixSzInch);
params.setYDensity(PixSzInch);
jpegEncoder.encode(img, params);
ostream.flush();
} catch (IOException ex) {
throw new TranscoderException(ex);
}
}