AddModernImageFromStream

Image handling, Modern image codecs, Streams

Description

Validates an AVIF, HEIF, HEIC, or JPEG XL stream, decodes its primary image in memory, and adds the result to the selected document

Syntax

Function TPDFlib.AddModernImageFromStream(
  InStream: TStream;
  Options: Integer= 8): Integer;

Parameters

InStreamSeekable stream containing a complete supported image from offset 0
OptionsImport mode from 0 to 8, with 8 retaining image data, alpha, ICC, and up to 16-bit samples

Option modes

0Image data with high bit depth
1Alpha as a greyscale image with high bit depth
2Image and alpha, forcing alpha to 8 bits
3Image data forced to 8 bits
4Alpha as a greyscale image forced to 8 bits
5Image and alpha both forced to 8 bits
6Image and alpha with high bit depth
7Image and ICC with high bit depth
8Image, alpha, and ICC with high bit depth

Return values

Returns the new ImageID or 0 when validation or decoding fails

Remarks

The built-in dynamic backend performs no temporary-file round trip and retains the original ICC profile bytes when creating the PNG bridge

AddImageFromStream also auto-detects these formats, while this method rejects every other container before invoking the decoder

See also

AddModernImageFromFile, AddModernImageFromString, SetModernImageCodecLibrary