Skip to main content

Jpeg to Tiff File Size problem

1 reply [Last post]
sureshkumark
Offline
Joined: 2007-08-17

Hi All,
I am very new to jai API. So If this qestion was asked before I don't know. I am using this API to convert a JPEG image to Tiff . The conversion was happening fine. But the problem is with the image size.

For Example if the JPEG image size is 228 KB. After converting to Tiff I am getting 2624KB. I am using follwoing code to achieve above functionality,

imageInputStream = new FileInputStream("C:\\Documents and Settings\\a1061\\Desktop\\2007-08-17\\IMAGE0001.jpg");

byte[] bytes = new byte[imageInputStream.available()];
imageInputStream.read(bytes);
SeekableStream firstImageStream = new ByteArraySeekableStream(bytes);

com.sun.media.jai.codec.ImageDecoder firstImageDecoder = ImageCodec.createImageDecoder("jpeg", firstImageStream, jpegParam);
firstRenderedImage = firstImageDecoder.decodeAsRenderedImage();

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", outputStream,
tiffParam);
encoder.encode(firstRenderedImage);
outputStream.close();
File newFile = new File( " path\\ + TIFFIMAGE.tiff"); FileOutputStream stream = new FileOutputStream(newFile);
stream.write(outputStream.toByteArray());
stream.close();

Please correct me if i am doing any mistake ...or any suggestion to reduce the file size... It is very urgent

Thanks
Suresh

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Nidel, Mike

The problem is your JPEG is compressed, and your TIFF is not.
If you examine the width and height of the image and calculate
the size, you will see it is probably correct - roughly 2600KB.

First of all, the API you are using to read/write the images
is the JAI Encoder/Decoder API. You should probably change to the
ImageIO API, and note that this is the JAI ImageIO tools mailing
list. If for some reason you need to keep using the JAI API, you
should ask your question on the JAI list to get a better answer.

Second, you should create your parameters for writing the TIFF so that
it compresses the image.

This information about TIFF compression might help you (but it might
not):

https://jai-imageio.dev.java.net/servlets/ReadMsg?list=interest&msgNo=16
40

I tried searching the list archives for more information but couldn't
find it.

> -----Original Message-----
> From: jai-imageio@javadesktop.org
> [mailto:jai-imageio@javadesktop.org]
> Sent: Friday, August 17, 2007 5:14 AM
> To: interest@jai-imageio.dev.java.net
> Subject: [JAI-IMAGEIO] Jpeg to Tiff File Size problem
>
> Hi All,
> I am very new to jai API. So If this qestion was asked
> before I don't know. I am using this API to convert a JPEG
> image to Tiff . The conversion was happening fine. But the
> problem is with the image size.
>
> For Example if the JPEG image size is 228 KB. After
> converting to Tiff I am getting 2624KB. I am using
> follwoing code to achieve above functionality,
>
> imageInputStream = new FileInputStream("C:\\Documents and
> Settings\\a1061\\Desktop\\2007-08-17\\IMAGE0001.jpg");
>
> byte[] bytes = new byte[imageInputStream.available()];
> imageInputStream.read(bytes);
> SeekableStream firstImageStream = new ByteArraySeekableStream(bytes);
>
> com.sun.media.jai.codec.ImageDecoder firstImageDecoder =
> ImageCodec.createImageDecoder("jpeg", firstImageStream, jpegParam);
> firstRenderedImage = firstImageDecoder.decodeAsRenderedImage();
>
>
> ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
>
> ImageEncoder encoder =
> ImageCodec.createImageEncoder("tiff", outputStream,
> tiffParam);
> encoder.encode(firstRenderedImage);
> outputStream.close();
> File newFile = new File( " path\\ + TIFFIMAGE.tiff");
> FileOutputStream
> stream = new FileOutputStream(newFile);
>
> stream.write(outputStream.toByteArray());
> stream.close();
>
> Please correct me if i am doing any mistake ...or any
> suggestion to reduce the file size... It is very urgent
>
> Thanks
> Suresh
> [Message sent by forum member 'sureshkumark' (sureshkumark)]
>
> http://forums.java.net/jive/thread.jspa?messageID=231298
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net