AddImageDirectFromString

Image handling

Description

Creates an image XObject directly from already-encoded image sample bytes instead of detecting a container format such as PNG, TIFF, or JPEG.

PDF version behaviour: the JBIG2Decode image filter requires PDF 1.4, while JPXDecode, Crypt, and image samples with BitsPerComponent = 16 require PDF 1.5. When a document is set below the required version and the save version is not locked, AddImageDirectFromString automatically raises the document version and records JBIG2Decode filter, JPXDecode filter, Crypt filter, or 16-bit image samples in AutoBumpedFeatures. If the caller locks a lower save version, the compatibility gate rejects the save with LastErrorCode 602.

Syntax

Delphi

function TPDFlib.AddImageDirectFromString(const Source: AnsiString; Width, Height, BitsPerComponent: Integer; const ColorSpace, Filter, Decode: WideString; Interpolate: Integer): Integer;

Parameters

SourceRaw or encoded image data to store in the image stream.
WidthImage width in pixels.
HeightImage height in pixels.
BitsPerComponentNumber of bits per sample component. PDF image dictionaries allow 1, 2, 4, and 8 in earlier versions; 16-bit samples are PDF 1.5.
ColorSpacePDF colour-space name or array text for the image dictionary, for example /DeviceGray, /DeviceRGB, or an indexed colour-space array.
FilterPDF stream filter name, such as FlateDecode, DCTDecode, or JPXDecode. Use an empty string for unfiltered data.
DecodeOptional PDF Decode array text. Pass an empty string when no Decode entry is needed.
InterpolateNonzero writes the /Interpolate true flag.

Return values

0The image could not be created, or the current PDF/A mode forbids the requested filter.
Non-zeroThe new ImageID. The created image is selected for subsequent image operations.

Remarks

PDF/A mode rejects LZWDecode in every part and rejects JBIG2Decode / JPXDecode in PDF/A-1. The caller is responsible for matching Source bytes to the declared ColorSpace, Filter, Decode, dimensions, and sample depth.

See also

AddImageFromString, AddImageFromFile, AddImageFromStream, DrawImage