Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

number of bytes in BufferedImage object  RSS feed

Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a BufferedImage object, is there a good way to get the number of bytes that are in it without writing it out to a file? Or do I have to convert it to a String and then convert that to a byte array and then get the length?

Currently, I write this BufferedImage out to a file, and I notice that when I use ImageIO's write method, it specifies the format as PNG or whatever. But I need to change this to use ImageIO's write method that writes out the BufferedImage to a stream, and the method that this stream gets sent to needs to know the length in bytes for something else. Problem is, I'm wondering if it's possible for you to know the length in bytes before you write it out into a particular format (PNG or whatever). So will I have to write this out to a temp file no matter what?
[ December 22, 2004: Message edited by: Stephen Huey ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!