SOLVED: Convert glyph data and assign it to TBitBtn lazarus / 39-Graphics ---------------------------------------------------------------------- SaraT · 2020-02-21 13:49 Good morning friends Please, see the attached image. Let's suppose that I just want to load an image with the glyph data. How can I convert this string to my glyph button? No image png, jpg, ico, no resource option... just this glyph data. Have a great day and many thanks. ---------------------------------------------------------------------- Handoko · 2020-02-21 14:09 Do something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Image1.Picture.Assign(BitBtn1.Glyph); If that is not what you want, you may try: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   Image1.Picture.LoadFromStream(aTStream); And if none above is what you want, you need to show us how you obtain the data. ---------------------------------------------------------------------- SaraT · 2020-02-21 14:21 Thanks Handoko I think is something like this but I dont know the correct way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Var  imageData : ???Begin  imageData := {361000...};  BitBtn1.Glyph := imageData;end; But is obvious that that won't work. I just want to use the data, nothing else: {361000...} Any idea? Thanks ---------------------------------------------------------------------- Handoko · 2020-02-21 14:34 That numbers is converted from binary data. First you need to convert the image data (which is binary data) to human readable text. Save it and use it later, but convert it back to binary data before used directly to the TBitmap. There are many ways to convert binary data to that readable text, you can search the web, using these keywords: data to hex string binary data to text And here is detailed explanation: https://en.wikipedia.org/wiki/Binary-to-text_encoding I believe FPC has such functions, but I don't know what they are. So I wrote mine and it can be used to convert my game data to importable string for used in the pascal code. Once you managed to do the conversion, you can use it in your Pascal code like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  ImageData: string;  AStream: TStringStream; begin  ImageData := // ... the human readble data  ConvertDataToStream(AStream); // your own function  Image1.Picture.LoadFromStream(AStream);end; Most Lazarus components internally use TStream for 'managing' data, so you can write your own ConvertDataToStream to 'send' the data to other components. Note: The 'binary' mentioned above is not the same as the binary you learned from school (Mathematics). ---------------------------------------------------------------------- SaraT · 2020-02-21 15:36 Many thanks Handoko I will try to do someyhing with it. In case someone already has the solution, please, share it with us. Best regards ---------------------------------------------------------------------- Handoko · 2020-02-21 15:56 If you're really interested, here are mine: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure HexStringToStream(const Input: string; Output: TMemoryStream;  OutputReturn: Boolean);var  Bookmark:   Int64;  Buffer:     array of Byte;  ResultSize: Integer;  i:          Integer;begin  ResultSize := Input.Length div 2;  SetLength(Buffer, ResultSize);  HexToBin(PChar(Input), PChar(Buffer), ResultSize);  Bookmark := Output.Position;  for i := 0 to (ResultSize-1) do    Output.WriteByte(Buffer[i]);  if OutputReturn then    Output.Position := Bookmark;end; procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,  FileName: string);var  Buffer: TStringList;  S:      string;  i:      Integer;begin  Buffer := TStringList.Create;  StreamToHexStringList(Input, Buffer);  with Buffer do  begin    for i := 0 to (Count-1) do    begin      S := '    ' + '''' + Strings[i] + '''';      case (i < Count-1) of        True:  S := S + '+';        False: S := S + ';';      end;      Buffer[i] := S;    end;    if (Count >= 0) then    begin      Insert(0, '  ' + ConstName + ' = ');    Insert(0, 'const');      SaveToFile(FileName);    end;    Free;  end;end; procedure StreamToHexStringList(Input: TMemoryStream; Output: TStringList);var  Buffer: array[0..31] of Byte;  Remain: Integer;  Todo:   Integer;  S:      string;  i:      Integer;begin  Input.Seek(0, soBeginning);  Remain := Input.Size;  while (Remain > 0) do  begin    Todo := 32;    if (Remain < 32) then      Todo := Remain;    Input.ReadBuffer(Buffer, Todo);    S := '';    for i := 0 to (Todo- 1) do      S := S + IntToHex(Buffer[i], 2);    Output.Add(S);    Remain := Remain - Todo;  end;end; I used them. It can convert and save any stream data to file so I can open the text file and copy/paste the string to use in my Pascal code. But that just how I do it, I believe many seniors will have better solutions. I don't think you will understand how to use my code. I recommend you to learn how to use TStream first. ---------------------------------------------------------------------- SaraT · 2020-02-21 16:59 You were right Handoko, I wasn't able to use your code, sorry is something advanced to me :/ Can you please try converting the below image data? If you convert the data, your Image1 control must have the icon check like the attached image (PNG). Many thanks Handoko. Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Picture.Data = {    1754506F727461626C654E6574776F726B477261706869634707000089504E47    0D0A1A0A0000000D4948445200000020000000200806000000737A7AF4000000    1974455874536F6674776172650041646F626520496D616765526561647971C9    653C000006E94944415478DA9C57596C5CD519FEEE328B671C8F27F1123B8EC7    4EAC246E425228B2828C315850158851D250D2A0AAA01050CB039548CB22E005    419E22A4BE5455050F08A1A651A3265836200812029E50D290D86984C7CB8C97    B13D5E66ECF16C77EBFF9F599871265E72ADFF5ECFBDE7FCDFF76FE7FC47C23A    AFF69750E1AAC149C878C692B03FF75E920AC4C235C9C0874BD378FFDBBF6271    3D7AA5B5BE3FF81A762815B8E0B4635FC7CF3AD05CEBC3F6AA3A58661AB17414    895484248A68720163E11066A25184E692304DF4272338FCD5690C931EEB4E08    280FBF8BBF391C78E18F8FBE8CF63DED58D4C6A12142B3D2B02C138669C0300C    2203A4B514E61667109A1D4670F6268233314CCE01A68E7FF4BD8A17499FB111    02B6AED3081CDC7D4FDD5BBF7E0F4BF0236E063111BE86E9F901CC4587914C1A    C2ED392D0E9B0D1ED7765494EF8453ADC7D0E415DC18BF4E7380C538427D7F81    8F466AEB21607BE81D8C3EF7C8EFEB0FB71DC3827915530BD771F5C773486926    643933492A31D3CADE6CAA8A5ACF43E4213BAE0C7F89C9D914266631F9E92B68    5A4962A51ADBC3A7113CDE7974EB63F73E8EA43282FE91FF6074B21F8A02C852    69E05B8858193295AE16785DBFC0F7FE5E043824614CF5BD82C642124A51CCDF    C6DFF736373FF09BF6A7603927F0DFC17F617CE626C8202872167C1D92AB8A84    360F9302B8B3B68BC2E0472C619437B4A3DEFF157A730ECB1190DA4E6277451D    3EF8C3AF9E47B957C740E002C6C3FFCB5BBE91CB2A28D19416A57F5268D8DC86    487C9004F75436E2ECC415CCF11839E77ACF0E9CFFE5DD0FA07C1330BF3488C0    F4F50CB8BC3EAB59687D208B019D6E7A360C12CD8F24FC50D414766DDB8BFA2A    A0AA05E719334FA0E97E54D9ED686DDDEE4359998C1F46CEDD193821A6A8D8BA    F7F6A0A3F90CB4021233B1AFD158B50FD51E098A0DADCD849923A03477E2C4EE    6DDB44ACA7233790D6A9C4943B0027CB0FB59E45A3E710F66F3D852D653EE111    1EA3591A910BA1BAC2072F7979C78338814C6AC16E73E1E9CD9BDC703A1D9822    02228936106F5AF53296EFF927766E3E96FF7674DF65418C07B1BE98368A2A4F    23DC4EF2BF1B4F33361370CAE4128F5B86CBE9463411142E5B69A1B586E5DDAD    0CFEDB2272A1D83799B1597D492D046FF9564180310536DD541EAC1B0951BF29    432B222092CACA08FF6F950267CBBDC5E0430B6771F1E611914BB9B2D4E84F55    1C19BF674A45CD4121411B8B6EE845B5CE809C481D8D67D0BDAB47B899418BC0    779706EFF9F138EC6A89445EB112CBB97A4DA497A06B7A7E90882DDDB6B87CD8    5F7B4A24D6A15D67415B0034127E76EFBA3DB8235B456BE5929C5B8F535A6667    5BE981A37B2EE707EFF41E23D08F10D3219EB78047087C90C0D972E5362B6729    02C8BA34915AA618D98A2688442AB85ABCBFC36BF759E2B911700E9B8D74EB46    8A36A99FC888743092188C2581D9E8385C6A5D7E3DE704BA387844285FED12E0    7E02B7AD62398953A9C3426C0ACB84C5988CCD04F4D8347AE2F472263A8672B5    29BF96F31E602785AC7C285A9A04BF17E0B9DD7215A26ED21D8E040501C6646C    2690BCF1093E5E5802C24B013850275C6565BDC016B15B4B91C883ABAB5BCEBA    38B4AC7B9630188B31199B09A4170298D612180E472C04E6FA5163EFCCD77B11    89E1E318899E17E0FCE4DF6B81E7085491CE20E9660CC6624CC656B3BDDAF2C0    27F893ED187ACA5D03A8A96842A5DA8288E1CF2D621912F4A377F449511DFC5E    80AFE1761EEB515A60A61DF04F0C883E91B11893B173FD80B9388178DDCFD16C    D9B047378268A9EE82212D216545F3C63018D7B62A657691B5C0399736298DF0    CA6DB8ECEFC3C89481B9095CBC760E1FD2A7852202FC23F01DAE3674E0294936    5CF174002D5BBA08258504E66F3D03ACE172765105592EC0877AA9654F60661E    7397DEC6B3BC4D70FC57B6641C0AD37F099F561FC4610B69D7223512DB3C6DF0    D87D347A0CA664E63BC952759EDB7854DA696AD42E285A2D81F709F0B169CC7E    FE3ABA69C418C962D6E82202ECB1342FFF4397F059CD411C594E1965516AA31C    72191ADC9D2853B688E38F29C5293C667E97148B8C64834B6E805739002FDAA8    1D1FA6C6E63B8C840CB67C9EC09F20DDA324EC4E7DD5B69C84BB155FE79FF126    F5898FD7136E75A584AA4D3EEA6828A6E5755456F6A2E38E61A4699109211C0D    8A52E36CE7845B0CA1F7EB33788786044866D76ACB0B497849B6D61FC0BEBB9E    C4BB76179AB893E1BD9C45918B27F0F2CA0B0C0BD7793A8ED1EBFFC61B933FA0    9F3E4F65934EDBD0D18CC44542F6A3DA5D8DDABD87D15DB91D8FA82E34DF72DA    234D7A1C2391317C3170013DCB6151E7742E12DD6F7CA347B3C2EFB62C113749    059735495941475D58F209926836C996B3C0DA9D1E4E4B79C4CE6D54B68B924A    94BD9E2DAFF4ED2C5E79FD5F800100550AFA734233AE390000000049454E44AE    426082  } ---------------------------------------------------------------------- Handoko · 2020-02-21 17:33 Sorry, I can't. I don't know what encoding is used internally by FPC to generate that data and how the data stored (like endianess, etc ... read more: https://en.wikipedia.org/wiki/Endianness). The readable binary data is not compatible with my functions. Using my function, the generated data from the image you provided is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  ImageData =     '89504E470D0A1A0A0000000D4948445200000020000000200806000000737A7A'+  'F40000001974455874536F6674776172650041646F626520496D616765526561'+  '647971C9653C000006E94944415478DA9C57596C5CD519FEEE328B671C8F27F1'+  '123B8EC74EAC246E425228B2828C315850158851D250D2A0AAA01050CB039548'+  'CB22E005419E22A4BE5455050F08A1A651A3265836200812029E50D290D86984'+  'C7CB8C97B13D5E66ECF16C77EBFF9F599871265E72ADFF5ECFBDE7FCDFF76FE7'+  'FC47C23AAFF69750E1AAC149C878C692B03FF75E920AC4C235C9C0874BD378FF'+  'DBBF62713D7AA5B5BE3FF81A762815B8E0B4635FC7CF3AD05CEBC3F6AA3A5866'+  '1AB17414895484248A68720163E11066A25184E692304DF4272338FCD5690C93'+  '1EEB4E08280FBF8BBF391C78E18F8FBE8CF63DED58D4C6A12142B3D2B02C1386'+  '69C0300C2203A4B514E61667109A1D4670F6268233314CCE01A68E7FF4BD8A17'+  '499FB11102B6AED3081CDC7D4FDD5BBF7E0F4BF0236E063111BE86E9F901CC45'+  '87914C1AC2ED392D0E9B0D1ED7765494EF8453ADC7D0E415DC18BF4E7380C538'+  '427D7F818F466AEB21607BE81D8C3EF7C8EFEB0FB71DC3827915530BD771F5C7'+  '73486926643933492A31D3CADE6CAA8A5ACF43E4213BAE0C7F89C9D914266631'+  'F9E92B685A4962A51ADBC3A7113CDE7974EB63F73E8EA43282FE91FF6074B21F'+  '8A02C85269E05B8858193295AE16785DBFC0F7FE5E043824614CF5BD82C64212'+  '4A51CCDFC6DFF736373FF09BF6A7603927F0DFC17F617CE626C8202872167C1D'+  '92AB8A84360F9302B8B3B68BC2E0472C619437B4A3DEFF157A730ECB1190DA4E'+  '6277451D3EF8C3AF9E47B957C740E002C6C3FFCB5BBE91CB2A28D19416A57F52'+  '68D8DC86487C9004F75436E2ECC415CCF11839E77ACF0E9CFFE5DD0FA07C1330'+  'BF3488C0F4F50CB8BC3EAB59687D208B019D6E7A360C12CD8F24FC50D414766D'+  'DB8BFA2AA0AA05E719334FA0E97E54D9ED686DDDEE4359998C1F46CEDD193821'+  'A6A8D8BAF7F6A0A3F90CB4021233B1AFD158B50FD51E098A0DADCD849923A034'+  '77E2C4EE6DDB44ACA7233790D6A9C4943B0027CB0FB59E45A3E710F66F3D852D'+  '653EE1111EA3591A910BA1BAC2072F7979C78338814C6AC16E73E1E9CD9BDC70'+  '3A1D982202228936106F5AF53296EFF927766E3E96FF7674DF65418C07B1BE98'+  '368A2A4F23DC4EF2BF1B4F33361370CAE4128F5B86CBE9463411142E5B69A1B5'+  '86E5DDAD0CFEDB2272A1D83799B1597D492D046FF9564180310536DD541EAC1B'+  '0951BF29432B222092CACA08FF6F950267CBBDC5E0430B6771F1E611914BB9B2'+  'D4E84F551C19BF674A45CD4121411B8B6EE845B5CE809C481D8D67D0BDAB47B8'+  '99418BC0779706EFF9F138EC6A89445EB112CBB97A4DA497A06B7A7E90882DDD'+  'B6B87CD85F7B4A24D6A15D67415B0034127E76EFBA3DB8235B456BE5929C5B8F'+  '535A66675BE981A37B2EE707EFF41E23D08F10D3219EB78047087C90C0D972E5'+  '362B672902C8BA34915AA618D98A2688442AB85ABCBFC36BF759E2B911700E9B'+  '8D74EB468A36A99FC888743092188C2581D9E8385C6A5D7E3DE704BA38784428'+  '5FED12E07E02B7AD62398953A9C3426C0ACB84C5988CCD04F4D8347AE2F47226'+  '3A8672B529BF96F31E602785AC7C285A9A04BF17E0B9DD7215A26ED21D8E0405'+  '01C6646C2690BCF1093E5E5802C24B013850275C6565BDC016B15B4B91C883AB'+  'AB5BCEBA38B4AC7B9630188B31199B09A4170298D612180E472C04E6FA5163EF'+  'CCD77B1189E1E318899E17E0FCE4DF6B81E7085491CE20E9660CC6624CC656B3'+  'BDDAF2C027F893ED187ACA5D03A8A96842A5DA8288E1CF2D621912F4A377F449'+  '511DFC5E80AFE1761EEB515A60A61DF04F0C883E91B11893B173FD80B9388178'+  'DDCFD16CD9B047378268A9EE82212D216545F3C63018D7B62A657691B5C03997'+  '36298DF0CA6DB8ECEFC3C89481B9095CBC760E1FD2A7852202FC23F01DAE3674'+  'E02949365CF174002D5BBA08258504E66F3D03ACE172765105592EC0877AA965'+  '4F60661E7397DEC6B3BC4D70FC57B6641C0AD37F099F561FC4610B69D7223512'+  'DB3C6DF0D87D347A0CA664E63BC952759EDB7854DA696AD42E285A2D81F709F0'+  'B169CC7EFE3ABA69C418C962D6E82202ECB1342FFF4397F059CD411C594E1965'+  '516AA31C72191ADC9D2853B688E38F29C5293C667E97148B8C64834B6E805739'+  '002FDAA81D1FA6C6E63B8C840CB67C9EC09F20DDA324EC4E7DD5B69C84BB155F'+  'E79FF126F5898FD7136E75A584AA4D3EEA6828A6E5755456F6A2E38E61A46991'+  '09211C0D8A52E36CE7845B0CA1F7EB33788786044866D76ACB0B497849B6D61F'+  'C0BEBB9EC4BB76179AB893E1BD9C45918B27F0F2CA0B0C0BD7793A8ED1EBFFC6'+  '1B933FA09F3E4F65934EDBD0D18CC44542F6A3DA5D8DDABD87D15DB91D8FA82E'+  '34DF72DA234D7A1C2391317C3170013DCB6151E7742E12DD6F7CA347B3C2EFB6'+  '2C113749059735495941475D58F209926836C996B3C0DA9D1E4E4B79C4CE6D54'+  'B68B924A94BD9E2DAFF4ED2C5E79FD5F800100550AFA734233AE390000000049'+  '454E44AE426082'; Something I'm sure about are, both encoded data are hexadecimal text and the last data are exactly the same: .....426082. Quote from: SaraT on February 21, 2020, 05:59:46 pmI wasn't able to use your code, sorry is something advanced to me :/ Learning how to use TStream isn't very hard. I believe you can understand it if you spend one or two days playing with it. After you are proficient in using TStream, you can do many powerful tricks. And you will understand how to use my functions by simply looking at the parameters of the functions. You may even able to write your own BinaryToText function. ---------------------------------------------------------------------- circular · 2020-02-21 18:16 Quote from: SaraT on February 21, 2020, 05:59:46 pmCode: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Picture.Data = {    1754506F727461626C654E6574776F726B477261706869634707000089504E47    0D0A1A0A0000000D4948445200000020000000200806000000737A7AF4000000    1974455874536F6674776172650041646F626520496D616765526561647971C9    653C000006E94944415478DA9C57596C5CD519FEEE328B671C8F27F1123B8EC7    4EAC246E425228B2828C315850158851D250D2A0AAA01050CB039548CB22E005    419E22A4BE5455050F08A1A651A3265836200812029E50D290D86984C7CB8C97    B13D5E66ECF16C77EBFF9F599871265E72ADFF5ECFBDE7FCDFF76FE7FC47C23A    AFF69750E1AAC149C878C692B03FF75E920AC4C235C9C0874BD378FFDBBF6271    3D7AA5B5BE3FF81A762815B8E0B4635FC7CF3AD05CEBC3F6AA3A58661AB17414    895484248A68720163E11066A25184E692304DF4272338FCD5690C931EEB4E08    280FBF8BBF391C78E18F8FBE8CF63DED58D4C6A12142B3D2B02C138669C0300C    2203A4B514E61667109A1D4670F6268233314CCE01A68E7FF4BD8A17499FB111    02B6AED3081CDC7D4FDD5BBF7E0F4BF0236E063111BE86E9F901CC4587914C1A    C2ED392D0E9B0D1ED7765494EF8453ADC7D0E415DC18BF4E7380C538427D7F81    8F466AEB21607BE81D8C3EF7C8EFEB0FB71DC3827915530BD771F5C773486926    643933492A31D3CADE6CAA8A5ACF43E4213BAE0C7F89C9D914266631F9E92B68    5A4962A51ADBC3A7113CDE7974EB63F73E8EA43282FE91FF6074B21F8A02C852    69E05B8858193295AE16785DBFC0F7FE5E043824614CF5BD82C642124A51CCDF    C6DFF736373FF09BF6A7603927F0DFC17F617CE626C8202872167C1D92AB8A84    360F9302B8B3B68BC2E0472C619437B4A3DEFF157A730ECB1190DA4E6277451D    3EF8C3AF9E47B957C740E002C6C3FFCB5BBE91CB2A28D19416A57F5268D8DC86    487C9004F75436E2ECC415CCF11839E77ACF0E9CFFE5DD0FA07C1330BF3488C0    F4F50CB8BC3EAB59687D208B019D6E7A360C12CD8F24FC50D414766DDB8BFA2A    A0AA05E719334FA0E97E54D9ED686DDDEE4359998C1F46CEDD193821A6A8D8BA    F7F6A0A3F90CB4021233B1AFD158B50FD51E098A0DADCD849923A03477E2C4EE    6DDB44ACA7233790D6A9C4943B0027CB0FB59E45A3E710F66F3D852D653EE111    1EA3591A910BA1BAC2072F7979C78338814C6AC16E73E1E9CD9BDC703A1D9822    02228936106F5AF53296EFF927766E3E96FF7674DF65418C07B1BE98368A2A4F    23DC4EF2BF1B4F33361370CAE4128F5B86CBE9463411142E5B69A1B586E5DDAD    0CFEDB2272A1D83799B1597D492D046FF9564180310536DD541EAC1B0951BF29    432B222092CACA08FF6F950267CBBDC5E0430B6771F1E611914BB9B2D4E84F55    1C19BF674A45CD4121411B8B6EE845B5CE809C481D8D67D0BDAB47B899418BC0    779706EFF9F138EC6A89445EB112CBB97A4DA497A06B7A7E90882DDDB6B87CD8    5F7B4A24D6A15D67415B0034127E76EFBA3DB8235B456BE5929C5B8F535A6667    5BE981A37B2EE707EFF41E23D08F10D3219EB78047087C90C0D972E5362B6729    02C8BA34915AA618D98A2688442AB85ABCBFC36BF759E2B911700E9B8D74EB46    8A36A99FC888743092188C2581D9E8385C6A5D7E3DE704BA387844285FED12E0    7E02B7AD62398953A9C3426C0ACB84C5988CCD04F4D8347AE2F472263A8672B5    29BF96F31E602785AC7C285A9A04BF17E0B9DD7215A26ED21D8E040501C6646C    2690BCF1093E5E5802C24B013850275C6565BDC016B15B4B91C883ABAB5BCEBA    38B4AC7B9630188B31199B09A4170298D612180E472C04E6FA5163EFCCD77B11    89E1E318899E17E0FCE4DF6B81E7085491CE20E9660CC6624CC656B3BDDAF2C0    27F893ED187ACA5D03A8A96842A5DA8288E1CF2D621912F4A377F449511DFC5E    80AFE1761EEB515A60A61DF04F0C883E91B11893B173FD80B9388178DDCFD16C    D9B047378268A9EE82212D216545F3C63018D7B62A657691B5C0399736298DF0    CA6DB8ECEFC3C89481B9095CBC760E1FD2A7852202FC23F01DAE3674E0294936    5CF174002D5BBA08258504E66F3D03ACE172765105592EC0877AA9654F60661E    7397DEC6B3BC4D70FC57B6641C0AD37F099F561FC4610B69D7223512DB3C6DF0    D87D347A0CA664E63BC952759EDB7854DA696AD42E285A2D81F709F0B169CC7E    FE3ABA69C418C962D6E82202ECB1342FFF4397F059CD411C594E1965516AA31C    72191ADC9D2853B688E38F29C5293C667E97148B8C64834B6E805739002FDAA8    1D1FA6C6E63B8C840CB67C9EC09F20DDA324EC4E7DD5B69C84BB155FE79FF126    F5898FD7136E75A584AA4D3EEA6828A6E5755456F6A2E38E61A4699109211C0D    8A52E36CE7845B0CA1F7EB33788786044866D76ACB0B497849B6D61FC0BEBB9E    C4BB76179AB893E1BD9C45918B27F0F2CA0B0C0BD7793A8ED1EBFFC61B933FA0    9F3E4F65934EDBD0D18CC44542F6A3DA5D8DDABD87D15DB91D8FA82E34DF72DA    234D7A1C2391317C3170013DCB6151E7742E12DD6F7CA347B3C2EFB62C113749    059735495941475D58F209926836C996B3C0DA9D1E4E4B79C4CE6D54B68B924A    94BD9E2DAFF4ED2C5E79FD5F800100550AFA734233AE390000000049454E44AE    426082  }In fact, this is the PNG content encoded in hexadecimal with some header. The header is: 1754506F727461626C654E6574776F726B4772617068696347070000 Next is the PNG: 89504E470D0A1A0A... ---------------------------------------------------------------------- Handoko · 2020-02-21 18:24 You have good eyesight. As far as I remember my code worked, I used it to convert and store images. But why without that header it still worked? Does it mean, that header is not 'really' needed? Maybe a kind of magic number added by FPC Lazarus for internal use or checksum. ---------------------------------------------------------------------- lucamar · 2020-02-21 19:26 Interesting exercise. It can probably be solved by using (or mimicing) the TReader for the glyph but I'll try to see how it could be coded. Not tonight, though. I'm quite busy (taking a rest now to read the forum ) ---------------------------------------------------------------------- winni · 2020-02-21 20:14 Quote from: circular on February 21, 2020, 07:16:21 pm In fact, this is the PNG content encoded in hexadecimal with some header. The header is: 1754506F727461626C654E6574776F726B4772617068696347070000 Next is the PNG: 89504E470D0A1A0A... The header is #$17TPortableNetworkGraphicG#07#00#00 whatever the "G" means Winni ---------------------------------------------------------------------- circular · 2020-02-21 20:50 Quote from: winni on February 21, 2020, 09:14:08 pmThe header is #$17TPortableNetworkGraphicG#07#00#00 whatever the "G" means Winni I suppose #17 is the length of the name of the class and then 'G'#07 is the size of the embedded data ($0747 = 1863) ---------------------------------------------------------------------- winni · 2020-02-21 20:58 Yes, with the two zeros this is Intel 32 bit Integer format! The bytes are always there where you won't exspect them. Learned it with Motorola .... Winni ---------------------------------------------------------------------- circular · 2020-02-21 22:21 Indeed ---------------------------------------------------------------------- SaraT · 2020-02-21 22:33 Thanks guys I hope one of you that have been working with Lazarus for many years can share with us (newest) the trick to to this. (in your free time, oviously) Best regards ---------------------------------------------------------------------- winni · 2020-02-22 00:54 Hi! Dirty midnight  hack: Copy the Picture.Data as you showed to the current directory of your Lazarus project. Call it pic.data. Then use this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure PicFromLFMData;const fIn = 'pic.data';      fOut='pic.png';      hex = ['0'..'9','A'..'F'];var ch,c1,c2 : char;    atWork,flipflop: Boolean;    txt: TextFile;    f : file of byte;    len : Integer = -1;    count : integer;     begin    assignFile (txt,fIn);    reset (txt);    assignFile(f,fOut);    rewrite(f);    atWork := false;    while not eof (txt) do       begin       read(txt,ch);       if ch = '{' then begin atWork := true; flipFlop := false; continue; end;       if ch = '}' then atWork := false;       if (ch in hex) and atWork then         begin         if not flipFlop then c1 := ch else            begin          c2 := ch;            if len = -1 then               begin             len := StrToInt ('$'+c1+c2)+4; // length integer               count := 0;               end;            if count > len then write (f,StrToInt('$'+c1+c2));            inc(count);            end;        flipflop:= not flipflop;         end; // in       end;     closeFile(txt);     closeFile(f);     showMessage ('done');    end;   Your picture is now in pic.png  - your icon as exspected. Winni ---------------------------------------------------------------------- SaraT · 2020-02-23 21:41 Quote from: winni on February 22, 2020, 01:54:16 amHi! Dirty midnight  hack: Copy the Picture.Data as you showed to the current directory of your Lazarus project. Call it pic.data. Then use this code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure PicFromLFMData;const fIn = 'pic.data';      fOut='pic.png';      hex = ['0'..'9','A'..'F'];var ch,c1,c2 : char;    atWork,flipflop: Boolean;    txt: TextFile;    f : file of byte;    len : Integer = -1;    count : integer;     begin    assignFile (txt,fIn);    reset (txt);    assignFile(f,fOut);    rewrite(f);    atWork := false;    while not eof (txt) do       begin       read(txt,ch);       if ch = '{' then begin atWork := true; flipFlop := false; continue; end;       if ch = '}' then atWork := false;       if (ch in hex) and atWork then         begin         if not flipFlop then c1 := ch else            begin          c2 := ch;            if len = -1 then               begin             len := StrToInt ('$'+c1+c2)+4; // length integer               count := 0;               end;            if count > len then write (f,StrToInt('$'+c1+c2));            inc(count);            end;        flipflop:= not flipflop;         end; // in       end;     closeFile(txt);     closeFile(f);     showMessage ('done');    end;   Your picture is now in pic.png  - your icon as exspected. Winni Hallo Winni... the picture data is in a text file. How can I load the picture data BUT from a variable? Sorry, I wasn't able to make it works and would not like my code depends on a file. Hope it is possible. Thanks. ---------------------------------------------------------------------- circular · 2020-02-23 22:13 You get the data from a string variable instead of file you more or less need to replace Code: Delphi  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     while not eof (txt) do       begin       read(txt,ch);by Code: Delphi  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     for i := 1 to length(strData) do       begin       ch := strData[i];where strData is your string variable. And remove the txt variable and what refers to it. ---------------------------------------------------------------------- SaraT · 2020-02-23 23:32 Quote from: circular on February 23, 2020, 11:13:06 pmYou get the data from a string variable instead of file you more or less need to replace Code: Delphi  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     while not eof (txt) do       begin       read(txt,ch);by Code: Delphi  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     for i := 1 to length(strData) do       begin       ch := strData[i];where strData is your string variable. And remove the txt variable and what refers to it. Thanks circular. The below code is to write to file. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i write (f,StrToInt('$'+c1+c2));How can I send the PNG to the TImage control? I was trying with this but I got error. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i stream.Write(f, sizeOf(StrToInt('$'+c1+c2)));stream.Position:= 0;png.LoadFromStream(stream);frmIndex.Image1.Picture.PNG.Assign(png); Thnx again ---------------------------------------------------------------------- Handoko · 2020-02-24 13:19 It seems you have problem using my functions. Here I show how to export image to a text file. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1: TImage;    procedure Button1Click(Sender: TObject);  end; var  Form1: TForm1; implementation procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,  FileName: string); forward; {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  aStream: TMemoryStream;begin  aStream := TMemoryStream.Create;  Image1.Picture.SaveToStream(aStream);  StreamToHexStringFile(aStream, 'ImageData', 'IMG.TXT');  aStream.Free;   ShowMessage('The image has been exported to IMG.TXT' +LineEnding+    'You can use it in your Pascal code by copy/pasting the text' +LineEnding+    'directly or using the compiler directive {$INCLUDE filename}.');end; //----------- ----------------------------------------------------------- procedure HexStringToStream(const Input: string; Output: TMemoryStream;  OutputReturn: Boolean);var  Bookmark:   Int64;  Buffer:     array of Byte;  ResultSize: Integer;  i:          Integer;begin  ResultSize := Input.Length div 2;  SetLength(Buffer, ResultSize);  HexToBin(PChar(Input), PChar(Buffer), ResultSize);  Bookmark := Output.Position;  for i := 0 to (ResultSize-1) do    Output.WriteByte(Buffer[i]);  if OutputReturn then    Output.Position := Bookmark;end; procedure StreamToHexStringList(Input: TMemoryStream; Output: TStringList);var  Buffer: array[0..31] of Byte;  Remain: Integer;  Todo:   Integer;  S:      string;  i:      Integer;begin  Input.Seek(0, soBeginning);  Remain := Input.Size;  while (Remain > 0) do  begin    Todo := 32;    if (Remain < 32) then      Todo := Remain;    Input.ReadBuffer(Buffer, Todo);    S := '';    for i := 0 to (Todo- 1) do      S := S + IntToHex(Buffer[i], 2);    Output.Add(S);    Remain := Remain - Todo;  end;end; procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,  FileName: string);var  Buffer: TStringList;  S:      string;  i:      Integer;begin  Buffer := TStringList.Create;  StreamToHexStringList(Input, Buffer);  with Buffer do  begin    for i := 0 to (Count-1) do    begin      S := '    ' + '''' + Strings[i] + '''';      case (i < Count-1) of        True:  S := S + '+';        False: S := S + ';';      end;      Buffer[i] := S;    end;    if (Count >= 0) then    begin      Insert(0, '  ' + ConstName + ' = ');    Insert(0, 'const');      SaveToFile(FileName);    end;    Free;  end;end; end. There are 3 functions, I let you to figure out yourself how to use the others. ---------------------------------------------------------------------- SaraT · 2020-02-24 15:22 Quote from: Handoko on February 24, 2020, 02:19:24 pmIt seems you have problem using my functions. Here I show how to export image to a text file. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1: TImage;    procedure Button1Click(Sender: TObject);  end; var  Form1: TForm1; implementation procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,  FileName: string); forward; {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);var  aStream: TMemoryStream;begin  aStream := TMemoryStream.Create;  Image1.Picture.SaveToStream(aStream);  StreamToHexStringFile(aStream, 'ImageData', 'IMG.TXT');  aStream.Free;   ShowMessage('The image has been exported to IMG.TXT' +LineEnding+    'You can use it in your Pascal code by copy/pasting the text' +LineEnding+    'directly or using the compiler directive {$INCLUDE filename}.');end; //----------- ----------------------------------------------------------- procedure HexStringToStream(const Input: string; Output: TMemoryStream;  OutputReturn: Boolean);var  Bookmark:   Int64;  Buffer:     array of Byte;  ResultSize: Integer;  i:          Integer;begin  ResultSize := Input.Length div 2;  SetLength(Buffer, ResultSize);  HexToBin(PChar(Input), PChar(Buffer), ResultSize);  Bookmark := Output.Position;  for i := 0 to (ResultSize-1) do    Output.WriteByte(Buffer[i]);  if OutputReturn then    Output.Position := Bookmark;end; procedure StreamToHexStringList(Input: TMemoryStream; Output: TStringList);var  Buffer: array[0..31] of Byte;  Remain: Integer;  Todo:   Integer;  S:      string;  i:      Integer;begin  Input.Seek(0, soBeginning);  Remain := Input.Size;  while (Remain > 0) do  begin    Todo := 32;    if (Remain < 32) then      Todo := Remain;    Input.ReadBuffer(Buffer, Todo);    S := '';    for i := 0 to (Todo- 1) do      S := S + IntToHex(Buffer[i], 2);    Output.Add(S);    Remain := Remain - Todo;  end;end; procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,  FileName: string);var  Buffer: TStringList;  S:      string;  i:      Integer;begin  Buffer := TStringList.Create;  StreamToHexStringList(Input, Buffer);  with Buffer do  begin    for i := 0 to (Count-1) do    begin      S := '    ' + '''' + Strings[i] + '''';      case (i < Count-1) of        True:  S := S + '+';        False: S := S + ';';      end;      Buffer[i] := S;    end;    if (Count >= 0) then    begin      Insert(0, '  ' + ConstName + ' = ');    Insert(0, 'const');      SaveToFile(FileName);    end;    Free;  end;end; end. There are 3 functions, I let you to figure out yourself how to use the others. Many thank Handoko, your code works well The case is that nobody has understood that I want to assign the picture data from a String to TImage Not from a TImage to file because we already have the image data. That's all, convert the string and assign it to the TImage(not file text to TImage). Thanks again. ---------------------------------------------------------------------- circular · 2020-02-24 18:36 Quote from: SaraT on February 24, 2020, 04:22:22 pmThe case is that nobody has understood that I want to assign the picture data from a String to TImage Not from a TImage to file because we already have the image data.I think each person is in a better position to know if they understood my dear. ---------------------------------------------------------------------- winni · 2020-02-24 21:55 Hi!  You are quiete unclear. To lift your secrets: * From where are the string data? From an lfm file? Then cicular gave you the answer. * Why do want to do that if you got the bitmap data already. Just for fun? I can't see no reason for you're action. Winni ---------------------------------------------------------------------- SaraT · 2020-02-25 04:07 Sorry guys, your answers are ok. But all your codes work with the Picture data from a file but what I want is load the Picture data from a variable. Lets say: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Var  picData : String; Begin picData := '{' +    '1754506F727461626C654E6574776F726B477261706869634707000089504E47...' The Picture data is loaded from a variable, not from a text file. I dont want to use any external file. I hope I am speaking clearly Thanks for your patience. ---------------------------------------------------------------------- PascalDragon · 2020-02-25 08:41 Here is how TPicture reads the data from the LFM stream: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TPicture.ReadData(Stream: TStream);var  GraphicClassName: Shortstring;  NewGraphic: TGraphic;  GraphicClass: TGraphicClass;  ok: boolean;begin  Stream.Read(GraphicClassName[0], 1);  Stream.Read(GraphicClassName[1], length(GraphicClassName));  GraphicClass := GetPicFileFormats.FindClassName(GraphicClassName);  NewGraphic := nil;  if GraphicClass <> nil then begin    NewGraphic := GraphicClass.Create;    ok:=false;    try      NewGraphic.ReadData(Stream);      ok:=true;    finally      if not ok then NewGraphic.Free;    end;  end;  FGraphic.Free;  FGraphic := NewGraphic;  if NewGraphic <> nil then begin    NewGraphic.OnChange := @Changed;    NewGraphic.OnProgress := @Progress;  end;  Changed(Self);end; You could try to adjust the code for your purpose though you'll have to roll your own registry of graphic types as GetPicFileFormats is private to the Graphics unit. Here's a proof of concept (untested): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  picdata: String = '{' +     '17545 …';  s: TStringStream;  GraphicClassName: String;  NewGraphic: TGraphic;  GraphicClass: TGraphicClass;  ok: Boolean;  pic: TPicture;begin  s := TStringStream.Create(picdata);  try    s.Read(GraphicClassName[0], 1);    s.Read(GraphicClassName[1], Length(GraphicClassName));    if GraphicClassName = 'TPortableNetworkGraphic' then      GraphicClass := TPortableNetworkGraphic    else      raise Exception.CreateFmt('Unknown graphic class: %s', [GraphicClassName]);    NewGraphic := GraphicClass.Create;    ok := False;    try      NewGraphic.ReadData(s);      ok := True;    finally      if not ok then        NewGraphic.Free;    end;    pic := TPicture.Create(Nil);  try      pic.Graphic := NewGraphic;      YourButton.Glyph := pic.Bitmap;    finally      pic.Free;    end;  finally    s.Free;  end;end; ---------------------------------------------------------------------- bytebites · 2020-02-25 12:03 Combining from previous replies one reply more. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  picData :=  '1754506F727461 ...'; function convert(picData: string): TPicture;var  stream: TStringStream;  ch: PChar;  i, num: integer;  Picture: TPicture;  GraphicClassName: ShortString;   function tohex(p: PChar): byte;  begin    case p^ of      '0'..'9': Result := Ord(p^) - 48;      'A'..'F': Result := Ord(p^) - 55;      else raise Exception.CreateFmt('Unexpected char: %s', [p^]);    end;  end; begin  i := length(picData);  ch := @picdata[1];  stream := tstringstream.Create;  while i > 0 do  begin    num := tohex(ch) * 16 + tohex(ch + 1);    stream.Write(num, 1);    ch := ch + 2;    i := i - 2;  end;  stream.position := 0;  stream.Read(GraphicClassName[0], 1);  stream.Read(GraphicClassName[1], Length(GraphicClassName));  if GraphicClassName <> 'TPortableNetworkGraphic' then    raise Exception.CreateFmt('Unknown graphic class: %s', [GraphicClassName]);  stream.Read(i, 4);  // assert(stream.Size-stream.Position=i,'size error');  Picture := TPicture.Create;  Picture.LoadFromStream(stream);  Result := Picture;  stream.Free;end; procedure TForm1.Button1Click(Sender: TObject);var  b: TPicture;begin  b := convert(picData);  image1.Picture := b;  BitBtn1.Glyph := b.Bitmap;  b.Free;end; ---------------------------------------------------------------------- SaraT · 2020-02-25 15:28 Many thanks guys It worked finally Happy coding ---------------------------------------------------------------------- AsleyCruz · 2020-02-25 19:51 Amazing! This would be useful to load PNG into custom components.