title: Make a BufferedImage use less RAM?
body: <p>I have java program that reads a jpegfile from the harddrive and uses it as the background image for various other things.  The image itself is stored in a <code>BufferImage</code> object like so:</p>
  
  <pre><code>BufferedImage background
  background = ImageIO.read(file)
  </code></pre>
  
  <p>This works great - the problem is that the <code>BufferedImage</code> object itself is enormous.  For example, a 215k jpeg file becomes a <code>BufferedImag</code>e object that's 4 megs and change.  The app in question can have some fairly large background images loaded, but whereas the jpegs are never more than a meg or two, the memory used to store the <code>BufferedImage</code> can quickly exceed 100s of megabytes.</p>
  
  <p>I assume all this is because the image is being stored in ram as raw RGB data, not compressed or optimized in any way.</p>
  
  <p>Is there a way to have it store the image in ram in a smaller format?  I'm in a situation where I have more slack on the CPU side than RAM, so a slight performance hit to get the image object's size back down towards the jpeg compression would be well worth it.</p>