Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert TIF to JPG without increasing Bit Depth

I am trying to convert TIF image to JPG image. For that I am using the following code :

    SeekableStream s = new FileSeekableStream(tiffUrl);
    TIFFDecodeParam param = null;
    ImageDecoder dec = ImageCodec.createImageDecoder(EXT_TIFFX, s, param);
    RenderedImage op = dec.decodeAsRenderedImage(0);
    FileOutputStream fos = new FileOutputStream(jpgUrl);
    JPEGEncodeParam jpgparam = new JPEGEncodeParam();
    jpgparam.setQuality(quality);               
    ImageEncoder en = ImageCodec.createImageEncoder(EXT_JEPGX, fos, jpgparam);
    en.encode(op);
    fos.flush();
    fos.close();
    s.close();

Before conversion my image size was approx 92KB and Bit Depth = 1 After conversion my new jpg image size is approx 1573KB and Bit Depth = 24

I need to manage my new image under 100KB. And I suppose this can be done if I control the Bit Depth to 1 itself.

Is there any solution helpful to perform this ?

like image 692
Shreyas Dave Avatar asked Feb 25 '14 13:02

Shreyas Dave


People also ask

Can I turn a tiff into a JPEG?

Make your TIFF images into JPGs.Choose File and select Save As. Or, choose File, then Export, and Save for Web (Legacy). Either process can be used to save CMYK, RGB, or grayscale images. Note: JPGs support only 8-bit images, so the bit depth will automatically be lowered on anything with a 16-bit image quality.

How do I reduce the bit depth of an image?

Open the image or frame you want to convert. Choose Palette > Set Pixel Depth and select a choice from the submenu (Figure 1). Table 1 shows how pixel depth relates to the number of colors in an image.

How do I convert TIFF to JPEG without losing quality?

An Easy Tip to Convert TIFF to JPG Without Losing Quality ​Right click on TIFF file, choose “Rename”. Then replace tiff with jpg as the file extension. Press Enter and choose “Use.


1 Answers

IMHO you should use Apache Commons Imaging as it is a advanced and complete imaging solution. I use this to write Tiff images to PDF. There are plenty of examples. Hope this will helps !!

like image 63
er_suthar Avatar answered Oct 07 '22 04:10

er_suthar