Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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
 
Rancher
Posts: 43016
76
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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
 
Sheriff
Posts: 22004
107
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Be Forthright When Cross Posting To Other Sites.
 
It's a tiny ad. At least, that's what she said.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic