PIMG __stdcall pdfCreateImageObj(PPDF IPDF, uint32_t Handle);
BOOL32 __stdcall pdfFreeImageObjEx(PPDF IPDF, void* ImagePtr);
function pdfCreateImageObj(const IPDF: PPDF; Handle: Cardinal): PIMG; stdcall;
function pdfFreeImageObjEx(const IPDF: PPDF; ImagePtr: Pointer): LongBool; stdcall;
Purpose. Mint a standalone, independently-lifetimed image object (PIMG) from an existing document image handle — its own private copy of the image bytes and metadata, registered in a global handle table separate from the document's own image list.
Description. pdfCreateImageObj resolves Handle via GetImageObjByHandle, allocates a TLumasImageObj, copies the transient byte buffer into its own owned OwnBuf array, remembers the originating Handle (consulted by pdfGetImageHandle below), and registers the object in a process-wide handle table (GHandleTable), returning the new PIMG. This object is entirely independent of the document once created — later mutating or replacing the source image (pdfReplaceImage, Image Insertion and Replacement) does not affect a PIMG already minted from it. pdfFreeImageObjEx looks the object up in the handle table, unregisters it, and frees it — the reverse of pdfCreateImageObj. IPDF is accepted by pdfFreeImageObjEx but not consulted — the object lookup and free happen purely through the global handle table, independent of which document handle is passed.
Parameters.
| Parameter | Description |
|---|---|
IPDF | Document handle. *(FreeEx: accepted but not consulted.)* |
Handle | *(Create only)* An existing document image handle to snapshot. |
ImagePtr | *(FreeEx only)* A PIMG previously returned by pdfCreateImageObj. |
Return value. pdfCreateImageObj: the new PIMG, or nil if Handle doesn't resolve. pdfFreeImageObjEx: True if ImagePtr resolved and was freed; False if it doesn't resolve in the handle table.
Remarks. A PIMG minted this way must be freed via pdfFreeImageObjEx, not pdfFreeImageObj (which instead operates on the document's own transient read-back buffer — see below); mixing the two up does not raise an error, but leaks the PIMG's owned memory since pdfFreeImageObj never touches the global handle table.
See also. pdfGetImageObjEx, pdfGetImageHandle.
C# (P/Invoke)
public static extern IntPtr pdfCreateImageObj(IntPtr IPDF, uint Handle);
Object Creation
pdfCreateImageObj
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.