Uses pngimage; {from PNG Image to hexadecimal string} function png2hex (PNG: tpngimage): string; var stream: tmemorystream; begin stream: = tmemorystream. create; PNG. savetostream (Stream); setlength (result, stream. size * 2); bintohex (stream. memory, pchar (result), stream. size); stream. free; end; {restore PNG image from hexadecimal string} procedure hex2png (STR: string; out PNG: tpngimage); var stream: tmemorystream; begin if not assigned (PNG) then PNG: = tpngimage. create; stream: = tmemorystream. create; stream. setsize (length (STR) Div 2); hextobin (pchar (STR), stream. memory, stream. size); PNG. loadfromstream (Stream); stream. free; end; {test} procedure tform1.button1click (Sender: tobject); var PNG: tpngimage; begin PNG: = tpngimage. create; PNG. loadfromfile ('C:/temp/test.png '); memo1.text: = png2hex (PNG); PNG. free; end; Procedure tform1.button2click (Sender: tobject); var PNG: tpngimage; begin PNG: = tpngimage. create; hex2png (memo1.text, PNG); canvas. draw (0, 0, PNG); PNG. free; end;
Parse the hex sequence stream of a PNG Image