image quality

I'm trying to take an image in a byte array format and convert it to 300dpi sized at 2550 x 3300. What I have is working fine, but the image quality is not as sharp as it should be. What exactly am I missing here:

SeekableStream ss = new ByteArraySeekableStream(imgContent);

PlanarImage image = JAI.create("stream", ss);

BufferedImage bufImage = image.getAsBufferedImage();

// The code up to g2d.drawImage is setting the image size

// to 2550w X 3300h.

TiledImage ti = new TiledImage(0,0,2550,3300,0,0,bufImage.getSampleModel(),bufImage.getColorModel());

Graphics2D g2d = ti.createGraphics();

AffineTransform at = new AffineTransform();

at.setToScale(1.2,1.2);

g2d.setTransform(at);

g2d.drawImage(bufImage,at,null);

ByteArrayOutputStream baout = new ByteArrayOutputStream();

TIFFEncodeParam param = new TIFFEncodeParam();

ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", baout, param);

param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);

// The code below sets the DPI of the image

//Start

// The code below will give u a 300 dpi x res and a 300 dpi y res

// 282 = X Res

// 283 = Y Res

// 296 = Res Unit

// 262 = Photometric Interpertation0 = WhiteIsZero, 1 = BlackIsZero

// 266 = FillOrder

// 277 = SamplesPerPixel

// 259 = Compression

TIFFField[] extras = new TIFFField[7];

extras[0] = new TIFFField(282, TIFFField.TIFF_RATIONAL, 1, (Object) new long[][] { {(long) 300, (long) 1 }, { (long) 0, (long) 0 } });

extras[1] = new TIFFField(283, TIFFField.TIFF_RATIONAL, 1, (Object) new long[][] { {(long) 300, (long) 1 }, { (long) 0, (long) 0 } });

extras[2] = new TIFFField(296, TIFFField.TIFF_SHORT, 1, (Object) new char[] { 2 });

extras[3] = new TIFFField(262, TIFFField.TIFF_SHORT, 1, (Object) new char[] { 0 });

extras[4] = new TIFFField(266, TIFFField.TIFF_SHORT, 1, (Object) new char[] { 1 });

extras[5] = new TIFFField(277, TIFFField.TIFF_SHORT, 1, (Object) new char[] { 1 });

extras[6] = new TIFFField(259, TIFFField.TIFF_SHORT, 1, (Object) new char[] { 4 });

param.setExtraFields(extras);

TIFFImageEncoder encoder1 = (TIFFImageEncoder) TIFFCodec.createImageEncoder("tiff", baout, param);

//End

encoder.encode(ti);

baout.close();

return baout.toByteArray();

}

[2431 byte] By [gaustina] at [2007-11-27 10:32:59]
# 1

You might get better response in the Multimedia and Imaging APIs section of this forum:

http://forum.java.sun.com/category.jspa?categoryID=9

Good luck.

prometheuzza at 2007-7-28 18:20:03 > top of Java-index,Java Essentials,Java Programming...