org.icepdf.core.util
Class ImageCache

java.lang.Object
  extended by org.icepdf.core.util.ImageCache

public class ImageCache
extends java.lang.Object

The ImageCache class is designed to cache image data to the file system. The cached file can then be read file the file system at a later time. The ImageCache class was created to help minimize the amount of data that has to be kept in memory when opening graphic heavy PDF files. The ImageCache class also speeds up the loading of a previously decoded image stream as it is much more effecient to read the decode image from file then it is to decode the image bit stream every time it is required.

The cached image is writen to the user temporary folder and is identeifed by "PDFImageStream" followed by seriers of numbers assigned from the objects hash code. Every time a new image cache is created the full path to the file is recored in the CacheManager class which allows the CacheManager to delete a documents cached images when the doucment is closed.

Since:
1.1

Constructor Summary
ImageCache(Library library)
          Create new instance of ImageCache
 
Method Summary
 void dispose(boolean cache, boolean imageRecoverableElsewise)
          Dispose of this objects resources
 long getLength()
          Return the number of bytes used by this images when it is cached.
 boolean isCachedSomehow()
           
 boolean isScaled()
           
 java.awt.image.BufferedImage readImage()
          Read the cached image file and return the corresponding buffered image.
static java.awt.image.BufferedImage scaleBufferedImage(java.awt.image.BufferedImage bim, int width, int height)
           
 void scaleImage(int width, int height)
           
 void setImage(java.awt.image.BufferedImage image)
          Writes Buffered imate to this object.
 void setIsScaled(boolean flag)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCache

public ImageCache(Library library)
Create new instance of ImageCache

Parameters:
library - reference to documents library
Method Detail

setImage

public void setImage(java.awt.image.BufferedImage image)
Writes Buffered imate to this object. If images caching is enabled, the images is written to disk, otherwise it is kept in memory.

Parameters:
image -

readImage

public java.awt.image.BufferedImage readImage()
Read the cached image file and return the corresponding buffered image.

Returns:
buffered image contained in the image cache temporary file.

dispose

public void dispose(boolean cache,
                    boolean imageRecoverableElsewise)
Dispose of this objects resources

Parameters:
cache - if true, image will be cached to disk, otherwise, image resources will be released.
imageRecoverableElsewise - If the ImageCache is not the only way of getting back at the image later

scaleImage

public void scaleImage(int width,
                       int height)

setIsScaled

public void setIsScaled(boolean flag)

getLength

public long getLength()
Return the number of bytes used by this images when it is cached.

Returns:
number of bytes of the cached file.

isScaled

public boolean isScaled()

isCachedSomehow

public boolean isCachedSomehow()

scaleBufferedImage

public static java.awt.image.BufferedImage scaleBufferedImage(java.awt.image.BufferedImage bim,
                                                              int width,
                                                              int height)