Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why ImageIO.write() creates image with double size than original  RSS feed

 
Rohit Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a jepg image. (39 KB size)
First I create a bufferedImage using ImageIO.read().
Then from the buffered image i create again jepg file (71 kb size).

why the size of new image is almost double? How to prevent it, and get back image with same size?

I simply used,

BufferedImage buffImg = ImageIO.read(originalFile); //create buffered imaeg from jepg file


ImageIO.write(buffImg, "jpg", newFile); //create jepg file from buffered image
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPEG is not a faithful round-trip format. That means if you read a JPEG into memory, and then write it back to disk, you won't get exactly the same file. The file size can differ, and so can the colors being used. The latter point especially is important to remember. If you need faithful round-tripping you need to use a format like TIFF or PNG.

As an aside, given today's disk sizes the difference in size seems inconsequential.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another cross poster.
http://forums.sun.com/thread.jspa?threadID=5354910
http://forums.sun.com/thread.jspa?threadID=5354912
 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Be Forthright When Cross Posting To Other Sites.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!