net.sf.image4j.codec.ico
Class ICOEncoder

java.lang.Object
  extended by net.sf.image4j.codec.ico.ICOEncoder

public class ICOEncoder
extends java.lang.Object

Encodes images in ICO format.

Author:
Ian McDonagh

Method Summary
static java.awt.image.BufferedImage convert(java.awt.image.BufferedImage img, int bpp)
          Utility method, which converts the given image to the specified colour depth.
static IconEntry createIconEntry(InfoHeader ih)
          Constructs an IconEntry from the given InfoHeader structure.
static void write(java.awt.image.BufferedImage image, java.io.File file)
          Encodes and writes a single image to file without colour depth conversion.
static void write(java.awt.image.BufferedImage image, int bpp, java.io.File file)
          Encodes and writes a single image to file with colour depth conversion using the specified value.
static void write(java.awt.image.BufferedImage image, int bpp, java.io.OutputStream os)
          Encodes and outputs a single image in ICO format.
static void write(java.awt.image.BufferedImage image, java.io.OutputStream os)
          Encodes and writes a single image without colour depth conversion.
static void write(java.util.List<java.awt.image.BufferedImage> images, java.io.File file)
          Encodes and writes multiple images to file without colour depth conversion.
static void write(java.util.List<java.awt.image.BufferedImage> images, int[] bpp, boolean[] compress, java.io.File file)
          Encodes and outputs a list of images in ICO format.
static void write(java.util.List<java.awt.image.BufferedImage> images, int[] bpp, boolean[] compress, java.io.OutputStream os)
          Encodes and outputs a list of images in ICO format.
static void write(java.util.List<java.awt.image.BufferedImage> images, int[] bpp, java.io.File file)
          Encodes and writes multiple images to file with the colour depth conversion using the specified values.
static void write(java.util.List<java.awt.image.BufferedImage> images, int[] bpp, java.io.OutputStream os)
          Encodes and outputs a list of images in ICO format.
static void write(java.util.List<java.awt.image.BufferedImage> images, java.io.OutputStream os)
          Encodes and writes multiple images without colour depth conversion.
static void writeAndBitmap(java.awt.image.BufferedImage img, LittleEndianOutputStream out)
          Encodes the AND bitmap for the given image according the its alpha channel (transparency) and writes it to the given output.
static void writeFileHeader(int count, int type, LittleEndianOutputStream out)
          Writes the ICO file header for an ICO containing the given number of images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

write

public static void write(java.awt.image.BufferedImage image,
                         java.io.File file)
                  throws java.io.IOException
Encodes and writes a single image to file without colour depth conversion.

Parameters:
image - the source image to encode
file - the output file to which the encoded image will be written
Throws:
java.io.IOException - if an exception occurs

write

public static void write(java.awt.image.BufferedImage image,
                         java.io.OutputStream os)
                  throws java.io.IOException
Encodes and writes a single image without colour depth conversion.

Parameters:
image - the source image to encode
os - the output to which the encoded image will be written
Throws:
java.io.IOException - if an exception occurs

write

public static void write(java.util.List<java.awt.image.BufferedImage> images,
                         java.io.OutputStream os)
                  throws java.io.IOException
Encodes and writes multiple images without colour depth conversion.

Parameters:
images - the list of source images to be encoded
os - the output to which the encoded image will be written
Throws:
java.io.IOException - if an error occurs

write

public static void write(java.util.List<java.awt.image.BufferedImage> images,
                         java.io.File file)
                  throws java.io.IOException
Encodes and writes multiple images to file without colour depth conversion.

Parameters:
images - the list of source images to encode
file - the file to which the encoded images will be written
Throws:
java.io.IOException - if an exception occurs

write

public static void write(java.util.List<java.awt.image.BufferedImage> images,
                         int[] bpp,
                         java.io.File file)
                  throws java.io.IOException
Encodes and writes multiple images to file with the colour depth conversion using the specified values.

Parameters:
images - the list of source images to encode
bpp - array containing desired colour depths for colour depth conversion
file - the output file to which the encoded images will be written
Throws:
java.io.IOException - if an error occurs

write

public static void write(java.util.List<java.awt.image.BufferedImage> images,
                         int[] bpp,
                         boolean[] compress,
                         java.io.File file)
                  throws java.io.IOException
Encodes and outputs a list of images in ICO format. The first image in the list will be at index #0 in the ICO file, the second at index #1, and so on.

Parameters:
images - List of images to encode, which will be output in the order supplied in the list.
bpp - Array containing the color depth (bits per pixel) for encoding the corresponding image at each index in the images list. If the array is null, no colour depth conversion will be performed. A colour depth value of -1 at a particular index indicates that no colour depth conversion should be performed for that image.
compress - Array containing the compression flag for the corresponding image at each index in the images list. If the array is null, no compression will be peformed. A value of true specifies that compression should be performed, while a value of false specifies that no compression should be performed.
file - the file to which the encoded images will be written.
Throws:
java.io.IOException - if an error occurred.
Since:
0.6

write

public static void write(java.awt.image.BufferedImage image,
                         int bpp,
                         java.io.File file)
                  throws java.io.IOException
Encodes and writes a single image to file with colour depth conversion using the specified value.

Parameters:
image - the source image to encode
bpp - the colour depth (bits per pixel) for the colour depth conversion, or -1 if no colour depth conversion should be performed
file - the output file to which the encoded image will be written
Throws:
java.io.IOException - if an error occurs

write

public static void write(java.awt.image.BufferedImage image,
                         int bpp,
                         java.io.OutputStream os)
                  throws java.io.IOException
Encodes and outputs a single image in ICO format. Convenience method, which calls write(java.util.List,int[],java.io.OutputStream).

Parameters:
image - The image to encode.
bpp - Colour depth (in bits per pixel) for the colour depth conversion, or -1 if no colour depth conversion should be performed.
os - The output to which the encoded image will be written.
Throws:
java.io.IOException - if an error occurs when trying to write the output.

write

public static void write(java.util.List<java.awt.image.BufferedImage> images,
                         int[] bpp,
                         java.io.OutputStream os)
                  throws java.io.IOException
Encodes and outputs a list of images in ICO format. The first image in the list will be at index #0 in the ICO file, the second at index #1, and so on.

Parameters:
images - List of images to encode, which will be output in the order supplied in the list.
bpp - Array containing the color depth (bits per pixel) for encoding the corresponding image at each index in the images list. If the array is null, no colour depth conversion will be performed. A colour depth value of -1 at a particular index indicates that no colour depth conversion should be performed for that image.
os - The output to which the encoded images will be written.
Throws:
java.io.IOException - if an error occurred.

write

public static void write(java.util.List<java.awt.image.BufferedImage> images,
                         int[] bpp,
                         boolean[] compress,
                         java.io.OutputStream os)
                  throws java.io.IOException
Encodes and outputs a list of images in ICO format. The first image in the list will be at index #0 in the ICO file, the second at index #1, and so on.

Parameters:
images - List of images to encode, which will be output in the order supplied in the list.
bpp - Array containing the color depth (bits per pixel) for encoding the corresponding image at each index in the images list. If the array is null, no colour depth conversion will be performed. A colour depth value of -1 at a particular index indicates that no colour depth conversion should be performed for that image.
compress - Array containing the compression flag for the corresponding image at each index in the images list. If the array is null, no compression will be peformed. A value of true specifies that compression should be performed, while a value of false specifies that no compression should be performed.
os - The output to which the encoded images will be written.
Throws:
java.io.IOException - if an error occurred.
Since:
0.6

writeFileHeader

public static void writeFileHeader(int count,
                                   int type,
                                   LittleEndianOutputStream out)
                            throws java.io.IOException
Writes the ICO file header for an ICO containing the given number of images.

Parameters:
count - the number of images in the ICO
type - one of TYPE_ICON or TYPE_CURSOR
out - the output to which the file header will be written
Throws:
java.io.IOException - if an error occurs

createIconEntry

public static IconEntry createIconEntry(InfoHeader ih)
Constructs an IconEntry from the given InfoHeader structure.

Parameters:
ih - the InfoHeader structure from which to construct the IconEntry structure.
Returns:
the IconEntry structure constructed from the IconEntry structure.

writeAndBitmap

public static void writeAndBitmap(java.awt.image.BufferedImage img,
                                  LittleEndianOutputStream out)
                           throws java.io.IOException
Encodes the AND bitmap for the given image according the its alpha channel (transparency) and writes it to the given output.

Parameters:
img - the image to encode as the AND bitmap.
out - the output to which the AND bitmap will be written
Throws:
java.io.IOException - if an error occurs.

convert

public static java.awt.image.BufferedImage convert(java.awt.image.BufferedImage img,
                                                   int bpp)
Utility method, which converts the given image to the specified colour depth.

Parameters:
img - the image to convert.
bpp - the target colour depth (bits per pixel) for the conversion.
Returns:
the given image converted to the specified colour depth.