DownsampleImagesEx
Images, Optimisation
Description
Per-class downsampling strategy for bitonal, greyscale and colour images
Syntax
Delphi
Function DownsampleImagesEx(ColorMaxDPI, GrayMaxDPI, BitonalMaxDPI, ColorQuality, GrayQuality, Flags: Integer): Integer;Parameters
| ColorMaxDPI | Maximum resolution for colour images with at least 24 DPI; images at or below it are left untouched |
|---|---|
| GrayMaxDPI | Maximum resolution for grayscale images with at least 24 DPI |
| BitonalMaxDPI | Maximum resolution for 1-bit images with at least 24 DPI; bitonal images always take the lossless path |
| ColorQuality | JPEG quality from 1 through 100 for colour images; 0 keeps the lossless path |
| GrayQuality | JPEG quality from 1 through 100 for grayscale images; 0 keeps the lossless path |
| Flags | Bit 1 (value 1) keeps the original stream unless the re-encoded bytes are smaller; other bits are ignored |
Return values
| 0 | No document, a budget below the 24 DPI floor, or no image needed resampling |
|---|---|
| N | Number 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 greyscale, 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);