ImageGear v26.4 - Updated
Developer Guide / How to Work with ... / Common Operations / Compress and Convert Images
In This Topic
    Compress and Convert Images
    In This Topic

    In ImageGear, both compression and conversion operations are closely related with Saving; these two operations are performed in ImageGear by setting some optional control parameters during saving operation.

    On one hand, image compression can be accomplished by manipulating the specific parameters of the filter corresponding to the target format File Formats Reference. Such a filter can be accessed by passing the appropriate ImGearFormats value to the Get method of ImGearFileFilters object; see Loading and Saving for more information.

    On the other hand, image conversion is associated with saving an image by specifying a relevant set of options through an instance of ImGearSaveOptions. ImageGear supports a variety of pixel formats (color spaces and channel depths). For more information, the user can refer to File Formats. However, most image file formats support only a limited set of pixel formats. For example, PNG format does not support CMYK color space, and JPEG Lossy format does not support storing 16-bit per channel pixel values. ImageGear provides conversion from a source image's pixel format into one of the pixel formats supported by the destination image file format.

    Availability of a specific pixel format for saving depends on the requested compression, saving options, and filter control parameters.

    ImageGear uses the following logic to select the pixel format for saving:

    • If the format filter directly supports saving of an image's pixel format, ImageGear uses this pixel format;
    • Otherwise, if the format filter supports saving of pixel formats that exceed the image's pixel format (so no image quality degradation occurs), ImageGear uses the one that takes least storage space;
    • Otherwise, ImageGear uses the pixel format that results in the least degradation of image quality.

    A special case is when the image color space has to be converted, and multiple choices of channel depths are available. In that case, ImageGear selects channel depths that are equal to the image's channel depths, rather than larger channel depths. This results in a slightly worse quality degradation, but avoids an unexpected increase in image size. For example, PNG format does not support CMYK color space, but it supports storing 8- or 16-bits per channel. ImageGear saves a 32-bit CMYK to PNG as 24-bit RGB rather than 48-bit RGB. ImageGear does not support conversion from multichannel truecolor color spaces (RGB, CMYK, etc.) into an indexed color space during saving.

    Refer to our CompressUsingOptions sample for a demonstration of how to combine image compression and conversion: set the conversion options mentioned above and the parameter Filters of ImGearSaveOptions with the local JPG filter designed for compression.