Wednesday, March 08, 2006

JAI create a tiff file - set resolution DPI

Java Forums - PLEASE HELP - JAI create a tiff file: "PLEASE HELP - JAI create a tiff file
Author: George_Azzopardi Posts: 3 Registered: 12/19/04
Dec 12, 2005 6:51 AM


Hi people,

I am trying to reate a TIFF file compressed for a Fax Server. The resolution of such an image must be 200dpi by 100dpi as per server requirements.

I am managing the create a tiff file with these requirements. However, since I am using a resolution of 200dpi by 100dpi, the final image is squashed vertically. The following is the code which I am using.

// loading the image
RenderedImage src = myCreateImage();
// this is a proprietary method which returns a RenderedImage

// Specifing the tompression Group
TIFFEncodeParam param = new TIFFEncodeParam();
param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);

//set the image resolution to 200 x 100
TIFFField[] extras = new TIFFField[2];
extras[0] = new TIFFField(282, TIFFField.TIFF_RATIONAL, 1, (Object)new long[][] {{(long)200, (long)1},{(long)0 ,(long)0}});
extras[1] = new TIFFField(283, TIFFField.TIFF_RATIONAL, 1, (Object)new long[][] {{(long)100, (long)1},{(long)0 ,(long)0}});
param.setExtraFields(extras);

OutputStream outputStream = new FileOutputStream ('c:/test.tif');
TIFFImageEncoder encoder = new TIFFImageEncoder (outputStream, param);
encoder.encode(src);
outputStream.close();
outputStream = null;

Any help would be highly appreciated

Thanks & Regards

George Azzopardi


Re: PLEASE HELP - JAI create a tiff f"

Maybe it's because you're not setting the resolution unit (tag 296)Example:TIFFField[] extras = new TIFFField[3];extras[0] = new TIFFField(282,TIFFField.TIFF_RATIONAL, 1, (Object)new long[][] {{200,(long)1},{(long)0 ,(long)0}}); //xextras[1] = new TIFFField(283,TIFFField.TIFF_RATIONAL, 1, (Object)new long[][] {{100,(long)1},{(long)0 ,(long)0}}); //y //set resolution unit to inchesextras[2] = new TIFFField(296, TIFFField.TIFF_SHORT, 1, (Object) new char[] {2}); //2 for inches param.setExtraFields(extras);

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home