DownsampleImagesEx

Images, Optimisation

Description

Per-class downsampling strategy for bitonal, grayscale and colour images

Syntax

Delphi

Function DownsampleImagesEx(ColorMaxDPI, GrayMaxDPI, BitonalMaxDPI, ColorQuality, GrayQuality, Flags: Integer): Integer;

Parameters

ColorMaxDPIMaximum resolution for colour images with at least 24 DPI; images at or below it are left untouched
GrayMaxDPIMaximum resolution for grayscale images with at least 24 DPI
BitonalMaxDPIMaximum resolution for 1-bit images with at least 24 DPI; bitonal images always take the lossless path
ColorQualityJPEG quality from 1 through 100 for colour images; 0 keeps the lossless path
GrayQualityJPEG quality from 1 through 100 for grayscale images; 0 keeps the lossless path
FlagsBit 1 (value 1) keeps the original stream unless the re-encoded bytes are smaller; other bits are ignored

Return values

0No document, a budget below the 24 DPI floor, or no image needed resampling
NNumber of images resampled and re-encoded

Remarks

Every image XObject is classified from /ColorSpace and /BitsPerComponent: 1-bit images are bitonal, DeviceGray, CalGray and single-channel ICCBased streams are grayscale, everything else is colour. Each class gets its own DPI budget and JPEG quality, so a typical mixed scan can keep line art at 300 DPI lossless while photographs drop to 150 DPI quality 75. Bitonal images always take the lossless PNG path because JPEG artefacts are unacceptable on 1-bit content. Flags bit 1 keeps the original stream when the re-encoded bytes are not smaller. Downsampling uses the same box filter and DPI estimation from page width as DownsampleImages.

Example

PDF.DownsampleImagesEx(150, 200, 300, 75, 85, 1);

See also

DownsampleImages, GetImageListItemNativeFormat