Image file formats often specify more information than is represented by CgDeviceIndependentImage. For example, image data in BMP format can either be uncompressed or compressed using run-length encoding. The application might need to know the data compression technique used by a loaded image's file so that the image can later be unloaded in the same way. The image file format objects preserve this extra information as part of their state when an image is loaded, and use this information when an image is unloaded.
Each of the CgFileFormat classes provides format-specific methods to access and change the extra information. These methods are outlined in the following sections.
Following these sections, an example illustrates how to manipulate extra information.
The following methods provide extra information preserved and used by the CgPCXFileFormat class:
The following methods provide extra information preserved and used by the CgPMBMPFileFormat class:
The following methods provide extra information preserved and used by the CgTIFFFileFormat class:
The following methods provide extra information preserved and used by the CgWinBMPFileFormat class:
The following code illustrates how to unload an image in Windows BMP format, using run-length encoding of the data if the image has a depth of 4 or 8. The device resolution and number of important colors are also specified.
| image format | image := self imageToUnload. format := CgWinBMPFileFormat new. format compression: 0. "No compression by default." image depth = 8 ifTrue: [format compression: 1]. "RLE8 compression." image depth = 4 ifTrue: [format compression: 2]. "RLE4 compression." format importantColors: (1 bitShift: image depth) - 3. "All but 3 colors are important. Approx. 75 dots per inch." format pelsPerMeter: 3000 @ 3000. format unload: image intoFile: 'img-out.bmp'