* @throws TranscoderException
* @see org.apache.flex.forks.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage(org.apache.flex.forks.batik.transcoder.image.PNGTranscoder, java.awt.image.BufferedImage, org.apache.flex.forks.batik.transcoder.TranscoderOutput)
*/
public void writeImage(TIFFTranscoder transcoder, BufferedImage img,
TranscoderOutput output) throws TranscoderException {
TranscodingHints hints = transcoder.getTranscodingHints();
TIFFEncodeParam params = new TIFFEncodeParam();
float PixSzMM = transcoder.getUserAgent().getPixelUnitToMillimeter();
// num Pixs in 100 Meters
int numPix = (int)(((1000 * 100) / PixSzMM) + 0.5);
int denom = 100 * 100; // Centimeters per 100 Meters;
long [] rational = {numPix, denom};
TIFFField [] fields = {
new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
TIFFField.TIFF_SHORT, 1,
new char [] { (char)3 }),
new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
TIFFField.TIFF_RATIONAL, 1,
new long [][] { rational }),
new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
TIFFField.TIFF_RATIONAL, 1,
new long [][] { rational })
};
params.setExtraFields(fields);
if (hints.containsKey(TIFFTranscoder.KEY_COMPRESSION_METHOD)) {
String method = (String)hints.get(TIFFTranscoder.KEY_COMPRESSION_METHOD);
if ("packbits".equals(method)) {
params.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
} else if ("deflate".equals(method)) {
params.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
/* TODO: NPE occurs when used.