0

Using below code to upload an image.

ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedImage img = ImageIO.read(new File("abc.tiff"));
ImageIO.write(img, "tiff", baos);
img.flush();  
img=null;

byte[] bytes2 = baos.toByteArray();
if(baos != null) {
    baos.flush();
    baos.close();
}

System.out.println("bytes2 size::::" + bytes2.length);

My original tiff image size is 119 kb and when I print the bytes of image I get 800974 bytes length.

Why the image size increases? and what can be the issue

2 Answers 2

0

Obviously your abc.tiff file is archived (TIFF format has an archived version), while img contains non-archived, unpacked data. That is why, your output is 782 kb instead of 119.

3
  • Not true. bytes2 size is that of an (re)encoded tiff image
    – leonbloy
    May 7, 2013 at 14:15
  • @leonbloy Well, I do not see difference between your and my answer. May be there is the misunderstanding: by term archived I meant compressed. Sorry for my bad English.
    – Andremoniy
    May 7, 2013 at 19:45
  • 1
    You are right in saying that img contains a raw image (and hence it's larger), but the OP is not measuring that, he is re-compressing img into a new TIFF (in memory, in baos), and measuring that.
    – leonbloy
    May 7, 2013 at 20:45
0

TIFF format, as most image formats, support lots of image modes and compression strategies. ImageIO.write() might not be very clever at optimizing, or it might need some tweaking. See eg here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.