Get file size of BufferedImage before writing the data

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-06-16T02:54:14Z Indexed on 2010/06/16 3:02 UTC
Read the original article Hit count: 170

Filed under:
|
|

I'm working on a Java program that needs to send an image (preferably in PNG format, though I could perhaps use another format if necessary) over the network. The logical way to do this is, of course, to first send the length of the PNG image data, then the data itself. Problem: I don't see any method in ImageIO or anywhere else that will give me the length of the image data. Does this exist somewhere in the Java 1.6 standard library?

I know I could just write it to a ByteArrayOutputStream and get the length of the resulting array, but before resorting that I wanted to make sure I'm not missing something built in. And besides, that makes an extra copy of the image data, which I'd rather not do if it's not necessary.

© Stack Overflow or respective owner

Related posts about java

Related posts about image