THotPDF.ExtractLoadedImageToStream Method
Writes one loaded image XObject directly to a caller-owned destination without creating a full-size byte array
Declaration
function ExtractLoadedImageToStream(ImageIndex: Integer;
Destination: TStream; Mode: THPDFLoadedImageStreamMode= lismEncoded): boolean;
Unit
HPDFDoc
Parameters
| Name | Purpose |
|---|---|
ImageIndex | Zero-based index from GetLoadedImageCount |
Destination | Caller-owned stream that receives bytes at its current position |
Mode | lismEncoded copies the native image payload, while lismDecoded executes the generic PDF stream filter chain |
Return value
Returns True when the selected image and extraction mode complete successfully
Usage notes
lismEncodedworks for native DCT, JPX, JBIG2, CCITT, Flate, LZW, and unfiltered payloads and restores the source positionlismDecodedsupports the generic Flate, LZW, ASCII85, ASCIIHex, and RunLength families through the bounded decode pipeline- Image-native terminal filters such as DCT or JPX remain encoded and should use
lismEncoded - Decoded extraction consumes per-chain and document-wide decode budgets
- A failed decoded write can leave partial bytes in the destination, so use a temporary stream when atomic output is required
Example
Output := TFileStream.Create('image.bin', fmCreate);
try
if not PDF.ExtractLoadedImageToStream(0, Output, lismEncoded) then
raise Exception.Create('Image extraction failed');
finally
Output.Free;
end;