Look at SaveImageToMemory for details.
function ImSaveImageToMemory(Ext: PAnsiChar; Data: Pointer; var Size: LongInt; const Image: TImageData): Boolean; cdecl;
ImagingExport (at line 97)