If we drag an image control into the form and set the picture, ALT+F12 can see that the form's source code has turned the image into a 16 string, as follows:
ObjectImage1:timage Left=536Top= -Width= theHeight= thePicture.data= {07544269746d61703e040000424d3e0400000000000036000000280000000700 00002b000000010018000000000008040000c40e0000 c40e0000000000000000 0001bbe7f4bce8f5bde9f6bbe7f4bde9f6bfebf8beeaf7000000b0e9f2b0e9f2 B0E9F2B0E9F2B1EAF3B2EBF4B1 Eaf3000000ade5f8ade5f8ace4f7ade5f8ace4 f7aae2f5abe3f60000009de4f89de4f89de4f89de4f89de4f89de4f89de4f800 00009DE4 F89de4f89de4f89de4f89de4f89de4f89de4f80000009be4f89be4f8 9be4f89be4f89be4f89be4f89be4f80000009be4f89be4f89be4f89be4f89be4 f89be4f89be4f80000009be4f89be4f89be4f89be4f89be4f89be4f89be4f800 00009ee5f99ee5f99ee5f99ee5f99ee5f99ee5f99ee5f9000000a0e5f9a0e5f9 A0e5f9a0e5f9a0e5f9a0e5f9a0e5f9000000a1e4f9a1e4f9a1e4f9a1e4f9a1e4 f9a1e4f9a1e4f9000000a1e6f9a1e6f9a1e6f9a1e6f9a1e6f9a1e6f9a1e6f900 0000a2e6f9a2e6f9a2e6f9a2e6f9a2e6f9a2e6f9a2e6f9000000a2e6f9a2e6f9 A2e6f9a2e6f9a2e6f9a2e6f9a2e6f9000000a5e6fba5e6fba5e6fba5e6fba5e6 Fba5e6fba5e6fb000000a8e7fba8e7fba8e7fba8e7fba8e7fba8e7fba8e7fb00 0000aae7fbaaE7fbaae7fbaae7fbaae7fbaae7fbaae7fb000000aae8faaae8fa Aae8faaae8faaae8faaae8faaae8fa000000abe9f9abe9f9abe9f9abe9f9abe9 f9abe9f9abe9f9000000aee9f9aee9f9aee9f9aee9f9aee9f9aee9f9aee9f900 0000b1e9fab1e9fab1e9fab1e9fab1e9fab1e9fab1e9fa000000b1e9fab1e9fa B1e9fab1e9fab1e9fab1e9fab1e9fa000000b4eafbb4eafbb4eafbb4eafbb4ea Fbb4eafbb4eafb000000b7ebfbb7ebfbb7ebfbb7ebfbb7ebfbb7ebfbb7ebfb00 0000b9ecfcb9ecfcb9ecfcb9ecfcb9ecfcb9ecfcb9ecfc000000b9ecfcb9ecfc B9ecfcb9ecfcb9ecfcb9ecfcb9ecfc000000b9ecfcb9ecfcb9ecfcb9ecfcb9ec Fcb9ecfcb9ecfc000000c0edfbc0edfbc0edfbc0edfbc0edfbc0edfbc0edfb00 0000c0edfbc0edfbc0edfbc0edfbc0edfbc0edfbc0edfb000000c2eefbc2eefb C2eefbc2eefbc2eefbc2eefbc2eefb000000c3effcc3effcc3effcc3effcc3ef Fcc3effcc3effc000000c5effbc5effbc5effbc5effbc5effbc5effbc5effb00 0000c8f0fcc8f0fcc8f0fcc8f0fcc8f0fcc8f0fcc8f0fc000000caf1facaf1fa CAF1FACAF1FACAF1FACAF1FACAF1FA000000CBF2FBCBF2FBCBF2FBCBF2FBCBF2 FBCBF2FBCBF2FB000000CEF1FBCEF1FBCef1fbcef1fbcef1fbcef1fbcef1fb00 0000CEF1FBCEF1FBCEF1FBCEF1FBCEF1FBCEF1FBCEF1FB000000CFF2FCCFF2FC CFF2FCCFF2FCCF F2fccff2fccff2fc000000d2f2fdd2f2fdd2f2fdd2f2fdd2f2 Fdd2f2fdd2f2fd000000d2f3fcd2f3fcd2f3fcd2f3fcd2f3fcd2f3fcd2f3fc00 0000d4f3fcd4f3fcd4f3fcd4f3fcd4f3fcd4f3fcd4f3fc000000d4f3fcd4f3fc D4F3FCD4F3FCD4F3FCD4F3FCD4F3FC000000D4F3FCD4F3FCD4F3FCD4F3FCD4F3 fcd4f3fcd4f3fc000000} End
Then in the actual application of how to implement the picture to 16, you can refer to the following conversion PNG example, the other format of the image conversion is basically similar:
uses pngimage; {from PNG image to hex string}function png2hex (png:tpngimage):string;varStream:tmemorystream;begin Stream:=tmemorystream.create; Png. Savetostream (stream); SetLength (Result, stream. Size*2); Bintohex (stream. Memory, PChar (Result), stream. Size); Stream. Free;end; {Restore a PNG image from a hexadecimal string}procedure hex2png (str:string; outpng:tpngimage);varStream:tmemorystream;beginifNot Assigned (PNG) then png: =tpngimage.create; Stream:=tmemorystream.create; Stream. SetSize (Length (str) div2); Hextobin (PChar (str), stream. Memory, Stream. Size); Png. Loadfromstream (stream); Stream. Free;end; {Test}procedure Tform1.button1click (sender:tobject);varpng:tpngimage;begin PNG:=tpngimage.create; Png. LoadFromFile ('C:\temp\test.png'); Memo1.text:=Png2hex (PNG); Png. Free;end; Procedure Tform1.button2click (sender:tobject);varpng:tpngimage;begin PNG:=tpngimage.create; Hex2png (Memo1.text, PNG); Canvas.draw (0,0, PNG); Png. Free;end;
Please note that this is particularly important:
At some point, you may need to parse the 16-based image generated from the source code, and you can refer to the following code:
When pasting, you want to remove the beginning of a small class of information: specifically to see their own saved picture string
Because the Tpngimage class was not found in the Pngimage control I used, I changed the code by modifying it
In my code, the code I loaded into the Timage control is:
{from PNG image to hex string}function png2hex (png:tpngobject):string;varStream:tmemorystream;begin Stream:=tmemorystream.create; Png. Savetostream (stream); SetLength (Result, stream. Size*2); Bintohex (stream. Memory, PChar (Result), stream. Size); Stream. Free;end; {Restore a PNG image from a hexadecimal string}procedure hex2png (str:string; outpng:tpngobject);varStream:tmemorystream;beginifNot Assigned (PNG) then png: =tpngobject.create; Stream:=tmemorystream.create; Stream. SetSize (Length (str) div2); Hextobin (PChar (str), stream. Memory, Stream. Size); Png. Loadfromstream (stream); Stream. Free;end;
Procedure Tform1.button4click (sender:tobject);varPng:tpngobject;begin//get a string from an image imagePNG: =tpngobject.create; TryPNG. Assign (Image1.Picture.Graphic); Memo1.text:=Png2hex (PNG); finallyPNG. Free; End;end;procedure Tform1.button5click (sender:tobject);varPng:tpngobject;begin//display to image image by stringPNG: =tpngobject.create; Tryhex2png (memo1.text,png); Image1.Picture.Graphic.Assign (PNG); finallyPNG. Free; End;end;
Too useful, so turn: Delphi 16 binary Bitmap data to bitmap