CompressImages

图像处理、文档属性

描述

设置调用后添加到文档的原始栅格图像数据所使用的默认压缩模式。该设置影响以未压缩像素上传的图像(BMP、原始像素数组);已压缩的图像(JPEG、JPEG 2000、CCITT、JBIG2)会保留现有编码并按原样存储,因为重新压缩会增大文件并降低质量

语法

Delphi

Function TPDFlib.CompressImages(Compress: Integer): Integer;

ActiveX

Function PDFlib::CompressImages(Compress As Long) As Long

DLL

int DLCompressImages(int InstanceID, int Compress);

参数

Compress0 — 不压缩地存储原始栅格图像
1 — 使用 flate 压缩原始栅格图像(/FlateDecode 过滤器)

返回值

0Compress 参数超出范围
1已更新图像压缩设置

备注

此设置仅影响调用后添加的图像。默认会压缩图像。与不支持 flate 解码图像流的下游渲染器集成时,偶尔会需要关闭压缩;正常使用时,请保持启用压缩

Flate 压缩无损,对于原始栅格图像的有损 JPEG 压缩,请在添加前将源编码为 JPEG,并使用 AddImageFromFile 或 AddImageFromStream,JPEG 字节流随后直接以内嵌 /DCTDecode 过滤器嵌入

示例

// Compress raw bitmaps but leave the pre-encoded JPEG as-is
PDF.CompressImages(1);
PDF.AddImageFromFile('logo.bmp');        // BMP -> flate compressed
PDF.AddImageFromFile('photo.jpg');       // JPEG bytes embedded directly (DCT)
PDF.AddImageFromFile('chart.png');       // PNG decoded -> flate compressed

另请参阅

CompressContent、CompressFonts、AddImageFromFile、AddImageFromStream