Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: SaraT on February 21, 2020, 02:49:39 pm

Title: SOLVED: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 21, 2020, 02:49:39 pm
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.


Title: Re: Convert glyph data and assign it to TBitBtn
Post by: Handoko on February 21, 2020, 03:09:19 pm
Do something like this:

Code: Pascal  [Select][+][-]
  1.   Image1.Picture.Assign(BitBtn1.Glyph);

If that is not what you want, you may try:

Code: Pascal  [Select][+][-]
  1.   Image1.Picture.LoadFromStream(aTStream);

And if none above is what you want, you need to show us how you obtain the data.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 21, 2020, 03:21:03 pm
Thanks Handoko
I think is something like this but I dont know the correct way:

Code: Pascal  [Select][+][-]
  1. Var
  2.   imageData : ???
  3. Begin
  4.   imageData := {361000...};
  5.   BitBtn1.Glyph := imageData;
  6. end;

But is obvious that that won't work. I just want to use the data, nothing else: {361000...}
Any idea?
Thanks :)
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: Handoko on February 21, 2020, 03:34:30 pm
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 (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][+][-]
  1. var
  2.   ImageData: string;
  3.   AStream: TStringStream;
  4.  
  5. begin
  6.   ImageData := // ... the human readble data
  7.   ConvertDataToStream(AStream); // your own function
  8.   Image1.Picture.LoadFromStream(AStream);
  9. 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).
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 21, 2020, 04:36:42 pm
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 :)
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: Handoko on February 21, 2020, 04:56:13 pm
If you're really interested, here are mine:

Code: Pascal  [Select][+][-]
  1. procedure HexStringToStream(const Input: string; Output: TMemoryStream;
  2.   OutputReturn: Boolean);
  3. var
  4.   Bookmark:   Int64;
  5.   Buffer:     array of Byte;
  6.   ResultSize: Integer;
  7.   i:          Integer;
  8. begin
  9.   ResultSize := Input.Length div 2;
  10.   SetLength(Buffer, ResultSize);
  11.   HexToBin(PChar(Input), PChar(Buffer), ResultSize);
  12.   Bookmark := Output.Position;
  13.   for i := 0 to (ResultSize-1) do
  14.     Output.WriteByte(Buffer[i]);
  15.   if OutputReturn then
  16.     Output.Position := Bookmark;
  17. end;
  18.  
  19. procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,
  20.   FileName: string);
  21. var
  22.   Buffer: TStringList;
  23.   S:      string;
  24.   i:      Integer;
  25. begin
  26.   Buffer := TStringList.Create;
  27.   StreamToHexStringList(Input, Buffer);
  28.   with Buffer do
  29.   begin
  30.     for i := 0 to (Count-1) do
  31.     begin
  32.       S := '    ' + '''' + Strings[i] + '''';
  33.       case (i < Count-1) of
  34.         True:  S := S + '+';
  35.         False: S := S + ';';
  36.       end;
  37.       Buffer[i] := S;
  38.     end;
  39.     if (Count >= 0) then
  40.     begin
  41.       Insert(0, '  ' + ConstName + ' = ');
  42.       Insert(0, 'const');
  43.       SaveToFile(FileName);
  44.     end;
  45.     Free;
  46.   end;
  47. end;
  48.  
  49. procedure StreamToHexStringList(Input: TMemoryStream; Output: TStringList);
  50. var
  51.   Buffer: array[0..31] of Byte;
  52.   Remain: Integer;
  53.   Todo:   Integer;
  54.   S:      string;
  55.   i:      Integer;
  56. begin
  57.   Input.Seek(0, soBeginning);
  58.   Remain := Input.Size;
  59.   while (Remain > 0) do
  60.   begin
  61.     Todo := 32;
  62.     if (Remain < 32) then
  63.       Todo := Remain;
  64.     Input.ReadBuffer(Buffer, Todo);
  65.     S := '';
  66.     for i := 0 to (Todo- 1) do
  67.       S := S + IntToHex(Buffer[i], 2);
  68.     Output.Add(S);
  69.     Remain := Remain - Todo;
  70.   end;
  71. 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.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 21, 2020, 05:59:46 pm
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][+][-]
  1. Picture.Data = {
  2.     1754506F727461626C654E6574776F726B477261706869634707000089504E47
  3.     0D0A1A0A0000000D4948445200000020000000200806000000737A7AF4000000
  4.     1974455874536F6674776172650041646F626520496D616765526561647971C9
  5.     653C000006E94944415478DA9C57596C5CD519FEEE328B671C8F27F1123B8EC7
  6.     4EAC246E425228B2828C315850158851D250D2A0AAA01050CB039548CB22E005
  7.     419E22A4BE5455050F08A1A651A3265836200812029E50D290D86984C7CB8C97
  8.     B13D5E66ECF16C77EBFF9F599871265E72ADFF5ECFBDE7FCDFF76FE7FC47C23A
  9.     AFF69750E1AAC149C878C692B03FF75E920AC4C235C9C0874BD378FFDBBF6271
  10.     3D7AA5B5BE3FF81A762815B8E0B4635FC7CF3AD05CEBC3F6AA3A58661AB17414
  11.     895484248A68720163E11066A25184E692304DF4272338FCD5690C931EEB4E08
  12.     280FBF8BBF391C78E18F8FBE8CF63DED58D4C6A12142B3D2B02C138669C0300C
  13.     2203A4B514E61667109A1D4670F6268233314CCE01A68E7FF4BD8A17499FB111
  14.     02B6AED3081CDC7D4FDD5BBF7E0F4BF0236E063111BE86E9F901CC4587914C1A
  15.     C2ED392D0E9B0D1ED7765494EF8453ADC7D0E415DC18BF4E7380C538427D7F81
  16.     8F466AEB21607BE81D8C3EF7C8EFEB0FB71DC3827915530BD771F5C773486926
  17.     643933492A31D3CADE6CAA8A5ACF43E4213BAE0C7F89C9D914266631F9E92B68
  18.     5A4962A51ADBC3A7113CDE7974EB63F73E8EA43282FE91FF6074B21F8A02C852
  19.     69E05B8858193295AE16785DBFC0F7FE5E043824614CF5BD82C642124A51CCDF
  20.     C6DFF736373FF09BF6A7603927F0DFC17F617CE626C8202872167C1D92AB8A84
  21.     360F9302B8B3B68BC2E0472C619437B4A3DEFF157A730ECB1190DA4E6277451D
  22.     3EF8C3AF9E47B957C740E002C6C3FFCB5BBE91CB2A28D19416A57F5268D8DC86
  23.     487C9004F75436E2ECC415CCF11839E77ACF0E9CFFE5DD0FA07C1330BF3488C0
  24.     F4F50CB8BC3EAB59687D208B019D6E7A360C12CD8F24FC50D414766DDB8BFA2A
  25.     A0AA05E719334FA0E97E54D9ED686DDDEE4359998C1F46CEDD193821A6A8D8BA
  26.     F7F6A0A3F90CB4021233B1AFD158B50FD51E098A0DADCD849923A03477E2C4EE
  27.     6DDB44ACA7233790D6A9C4943B0027CB0FB59E45A3E710F66F3D852D653EE111
  28.     1EA3591A910BA1BAC2072F7979C78338814C6AC16E73E1E9CD9BDC703A1D9822
  29.     02228936106F5AF53296EFF927766E3E96FF7674DF65418C07B1BE98368A2A4F
  30.     23DC4EF2BF1B4F33361370CAE4128F5B86CBE9463411142E5B69A1B586E5DDAD
  31.     0CFEDB2272A1D83799B1597D492D046FF9564180310536DD541EAC1B0951BF29
  32.     432B222092CACA08FF6F950267CBBDC5E0430B6771F1E611914BB9B2D4E84F55
  33.     1C19BF674A45CD4121411B8B6EE845B5CE809C481D8D67D0BDAB47B899418BC0
  34.     779706EFF9F138EC6A89445EB112CBB97A4DA497A06B7A7E90882DDDB6B87CD8
  35.     5F7B4A24D6A15D67415B0034127E76EFBA3DB8235B456BE5929C5B8F535A6667
  36.     5BE981A37B2EE707EFF41E23D08F10D3219EB78047087C90C0D972E5362B6729
  37.     02C8BA34915AA618D98A2688442AB85ABCBFC36BF759E2B911700E9B8D74EB46
  38.     8A36A99FC888743092188C2581D9E8385C6A5D7E3DE704BA387844285FED12E0
  39.     7E02B7AD62398953A9C3426C0ACB84C5988CCD04F4D8347AE2F472263A8672B5
  40.     29BF96F31E602785AC7C285A9A04BF17E0B9DD7215A26ED21D8E040501C6646C
  41.     2690BCF1093E5E5802C24B013850275C6565BDC016B15B4B91C883ABAB5BCEBA
  42.     38B4AC7B9630188B31199B09A4170298D612180E472C04E6FA5163EFCCD77B11
  43.     89E1E318899E17E0FCE4DF6B81E7085491CE20E9660CC6624CC656B3BDDAF2C0
  44.     27F893ED187ACA5D03A8A96842A5DA8288E1CF2D621912F4A377F449511DFC5E
  45.     80AFE1761EEB515A60A61DF04F0C883E91B11893B173FD80B9388178DDCFD16C
  46.     D9B047378268A9EE82212D216545F3C63018D7B62A657691B5C0399736298DF0
  47.     CA6DB8ECEFC3C89481B9095CBC760E1FD2A7852202FC23F01DAE3674E0294936
  48.     5CF174002D5BBA08258504E66F3D03ACE172765105592EC0877AA9654F60661E
  49.     7397DEC6B3BC4D70FC57B6641C0AD37F099F561FC4610B69D7223512DB3C6DF0
  50.     D87D347A0CA664E63BC952759EDB7854DA696AD42E285A2D81F709F0B169CC7E
  51.     FE3ABA69C418C962D6E82202ECB1342FFF4397F059CD411C594E1965516AA31C
  52.     72191ADC9D2853B688E38F29C5293C667E97148B8C64834B6E805739002FDAA8
  53.     1D1FA6C6E63B8C840CB67C9EC09F20DDA324EC4E7DD5B69C84BB155FE79FF126
  54.     F5898FD7136E75A584AA4D3EEA6828A6E5755456F6A2E38E61A4699109211C0D
  55.     8A52E36CE7845B0CA1F7EB33788786044866D76ACB0B497849B6D61FC0BEBB9E
  56.     C4BB76179AB893E1BD9C45918B27F0F2CA0B0C0BD7793A8ED1EBFFC61B933FA0
  57.     9F3E4F65934EDBD0D18CC44542F6A3DA5D8DDABD87D15DB91D8FA82E34DF72DA
  58.     234D7A1C2391317C3170013DCB6151E7742E12DD6F7CA347B3C2EFB62C113749
  59.     059735495941475D58F209926836C996B3C0DA9D1E4E4B79C4CE6D54B68B924A
  60.     94BD9E2DAFF4ED2C5E79FD5F800100550AFA734233AE390000000049454E44AE
  61.     426082
  62.   }
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: Handoko on February 21, 2020, 06:33:09 pm
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 (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][+][-]
  1. const
  2.   ImageData =
  3.     '89504E470D0A1A0A0000000D4948445200000020000000200806000000737A7A'+
  4.     'F40000001974455874536F6674776172650041646F626520496D616765526561'+
  5.     '647971C9653C000006E94944415478DA9C57596C5CD519FEEE328B671C8F27F1'+
  6.     '123B8EC74EAC246E425228B2828C315850158851D250D2A0AAA01050CB039548'+
  7.     'CB22E005419E22A4BE5455050F08A1A651A3265836200812029E50D290D86984'+
  8.     'C7CB8C97B13D5E66ECF16C77EBFF9F599871265E72ADFF5ECFBDE7FCDFF76FE7'+
  9.     'FC47C23AAFF69750E1AAC149C878C692B03FF75E920AC4C235C9C0874BD378FF'+
  10.     'DBBF62713D7AA5B5BE3FF81A762815B8E0B4635FC7CF3AD05CEBC3F6AA3A5866'+
  11.     '1AB17414895484248A68720163E11066A25184E692304DF4272338FCD5690C93'+
  12.     '1EEB4E08280FBF8BBF391C78E18F8FBE8CF63DED58D4C6A12142B3D2B02C1386'+
  13.     '69C0300C2203A4B514E61667109A1D4670F6268233314CCE01A68E7FF4BD8A17'+
  14.     '499FB11102B6AED3081CDC7D4FDD5BBF7E0F4BF0236E063111BE86E9F901CC45'+
  15.     '87914C1AC2ED392D0E9B0D1ED7765494EF8453ADC7D0E415DC18BF4E7380C538'+
  16.     '427D7F818F466AEB21607BE81D8C3EF7C8EFEB0FB71DC3827915530BD771F5C7'+
  17.     '73486926643933492A31D3CADE6CAA8A5ACF43E4213BAE0C7F89C9D914266631'+
  18.     'F9E92B685A4962A51ADBC3A7113CDE7974EB63F73E8EA43282FE91FF6074B21F'+
  19.     '8A02C85269E05B8858193295AE16785DBFC0F7FE5E043824614CF5BD82C64212'+
  20.     '4A51CCDFC6DFF736373FF09BF6A7603927F0DFC17F617CE626C8202872167C1D'+
  21.     '92AB8A84360F9302B8B3B68BC2E0472C619437B4A3DEFF157A730ECB1190DA4E'+
  22.     '6277451D3EF8C3AF9E47B957C740E002C6C3FFCB5BBE91CB2A28D19416A57F52'+
  23.     '68D8DC86487C9004F75436E2ECC415CCF11839E77ACF0E9CFFE5DD0FA07C1330'+
  24.     'BF3488C0F4F50CB8BC3EAB59687D208B019D6E7A360C12CD8F24FC50D414766D'+
  25.     'DB8BFA2AA0AA05E719334FA0E97E54D9ED686DDDEE4359998C1F46CEDD193821'+
  26.     'A6A8D8BAF7F6A0A3F90CB4021233B1AFD158B50FD51E098A0DADCD849923A034'+
  27.     '77E2C4EE6DDB44ACA7233790D6A9C4943B0027CB0FB59E45A3E710F66F3D852D'+
  28.     '653EE1111EA3591A910BA1BAC2072F7979C78338814C6AC16E73E1E9CD9BDC70'+
  29.     '3A1D982202228936106F5AF53296EFF927766E3E96FF7674DF65418C07B1BE98'+
  30.     '368A2A4F23DC4EF2BF1B4F33361370CAE4128F5B86CBE9463411142E5B69A1B5'+
  31.     '86E5DDAD0CFEDB2272A1D83799B1597D492D046FF9564180310536DD541EAC1B'+
  32.     '0951BF29432B222092CACA08FF6F950267CBBDC5E0430B6771F1E611914BB9B2'+
  33.     'D4E84F551C19BF674A45CD4121411B8B6EE845B5CE809C481D8D67D0BDAB47B8'+
  34.     '99418BC0779706EFF9F138EC6A89445EB112CBB97A4DA497A06B7A7E90882DDD'+
  35.     'B6B87CD85F7B4A24D6A15D67415B0034127E76EFBA3DB8235B456BE5929C5B8F'+
  36.     '535A66675BE981A37B2EE707EFF41E23D08F10D3219EB78047087C90C0D972E5'+
  37.     '362B672902C8BA34915AA618D98A2688442AB85ABCBFC36BF759E2B911700E9B'+
  38.     '8D74EB468A36A99FC888743092188C2581D9E8385C6A5D7E3DE704BA38784428'+
  39.     '5FED12E07E02B7AD62398953A9C3426C0ACB84C5988CCD04F4D8347AE2F47226'+
  40.     '3A8672B529BF96F31E602785AC7C285A9A04BF17E0B9DD7215A26ED21D8E0405'+
  41.     '01C6646C2690BCF1093E5E5802C24B013850275C6565BDC016B15B4B91C883AB'+
  42.     'AB5BCEBA38B4AC7B9630188B31199B09A4170298D612180E472C04E6FA5163EF'+
  43.     'CCD77B1189E1E318899E17E0FCE4DF6B81E7085491CE20E9660CC6624CC656B3'+
  44.     'BDDAF2C027F893ED187ACA5D03A8A96842A5DA8288E1CF2D621912F4A377F449'+
  45.     '511DFC5E80AFE1761EEB515A60A61DF04F0C883E91B11893B173FD80B9388178'+
  46.     'DDCFD16CD9B047378268A9EE82212D216545F3C63018D7B62A657691B5C03997'+
  47.     '36298DF0CA6DB8ECEFC3C89481B9095CBC760E1FD2A7852202FC23F01DAE3674'+
  48.     'E02949365CF174002D5BBA08258504E66F3D03ACE172765105592EC0877AA965'+
  49.     '4F60661E7397DEC6B3BC4D70FC57B6641C0AD37F099F561FC4610B69D7223512'+
  50.     'DB3C6DF0D87D347A0CA664E63BC952759EDB7854DA696AD42E285A2D81F709F0'+
  51.     'B169CC7EFE3ABA69C418C962D6E82202ECB1342FFF4397F059CD411C594E1965'+
  52.     '516AA31C72191ADC9D2853B688E38F29C5293C667E97148B8C64834B6E805739'+
  53.     '002FDAA81D1FA6C6E63B8C840CB67C9EC09F20DDA324EC4E7DD5B69C84BB155F'+
  54.     'E79FF126F5898FD7136E75A584AA4D3EEA6828A6E5755456F6A2E38E61A46991'+
  55.     '09211C0D8A52E36CE7845B0CA1F7EB33788786044866D76ACB0B497849B6D61F'+
  56.     'C0BEBB9EC4BB76179AB893E1BD9C45918B27F0F2CA0B0C0BD7793A8ED1EBFFC6'+
  57.     '1B933FA09F3E4F65934EDBD0D18CC44542F6A3DA5D8DDABD87D15DB91D8FA82E'+
  58.     '34DF72DA234D7A1C2391317C3170013DCB6151E7742E12DD6F7CA347B3C2EFB6'+
  59.     '2C113749059735495941475D58F209926836C996B3C0DA9D1E4E4B79C4CE6D54'+
  60.     'B68B924A94BD9E2DAFF4ED2C5E79FD5F800100550AFA734233AE390000000049'+
  61.     '454E44AE426082';

Something I'm sure about are, both encoded data are hexadecimal text and the last data are exactly the same: .....426082.

I 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.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: circular on February 21, 2020, 07:16:21 pm
Code: Text  [Select][+][-]
  1. Picture.Data = {
  2.     1754506F727461626C654E6574776F726B477261706869634707000089504E47
  3.     0D0A1A0A0000000D4948445200000020000000200806000000737A7AF4000000
  4.     1974455874536F6674776172650041646F626520496D616765526561647971C9
  5.     653C000006E94944415478DA9C57596C5CD519FEEE328B671C8F27F1123B8EC7
  6.     4EAC246E425228B2828C315850158851D250D2A0AAA01050CB039548CB22E005
  7.     419E22A4BE5455050F08A1A651A3265836200812029E50D290D86984C7CB8C97
  8.     B13D5E66ECF16C77EBFF9F599871265E72ADFF5ECFBDE7FCDFF76FE7FC47C23A
  9.     AFF69750E1AAC149C878C692B03FF75E920AC4C235C9C0874BD378FFDBBF6271
  10.     3D7AA5B5BE3FF81A762815B8E0B4635FC7CF3AD05CEBC3F6AA3A58661AB17414
  11.     895484248A68720163E11066A25184E692304DF4272338FCD5690C931EEB4E08
  12.     280FBF8BBF391C78E18F8FBE8CF63DED58D4C6A12142B3D2B02C138669C0300C
  13.     2203A4B514E61667109A1D4670F6268233314CCE01A68E7FF4BD8A17499FB111
  14.     02B6AED3081CDC7D4FDD5BBF7E0F4BF0236E063111BE86E9F901CC4587914C1A
  15.     C2ED392D0E9B0D1ED7765494EF8453ADC7D0E415DC18BF4E7380C538427D7F81
  16.     8F466AEB21607BE81D8C3EF7C8EFEB0FB71DC3827915530BD771F5C773486926
  17.     643933492A31D3CADE6CAA8A5ACF43E4213BAE0C7F89C9D914266631F9E92B68
  18.     5A4962A51ADBC3A7113CDE7974EB63F73E8EA43282FE91FF6074B21F8A02C852
  19.     69E05B8858193295AE16785DBFC0F7FE5E043824614CF5BD82C642124A51CCDF
  20.     C6DFF736373FF09BF6A7603927F0DFC17F617CE626C8202872167C1D92AB8A84
  21.     360F9302B8B3B68BC2E0472C619437B4A3DEFF157A730ECB1190DA4E6277451D
  22.     3EF8C3AF9E47B957C740E002C6C3FFCB5BBE91CB2A28D19416A57F5268D8DC86
  23.     487C9004F75436E2ECC415CCF11839E77ACF0E9CFFE5DD0FA07C1330BF3488C0
  24.     F4F50CB8BC3EAB59687D208B019D6E7A360C12CD8F24FC50D414766DDB8BFA2A
  25.     A0AA05E719334FA0E97E54D9ED686DDDEE4359998C1F46CEDD193821A6A8D8BA
  26.     F7F6A0A3F90CB4021233B1AFD158B50FD51E098A0DADCD849923A03477E2C4EE
  27.     6DDB44ACA7233790D6A9C4943B0027CB0FB59E45A3E710F66F3D852D653EE111
  28.     1EA3591A910BA1BAC2072F7979C78338814C6AC16E73E1E9CD9BDC703A1D9822
  29.     02228936106F5AF53296EFF927766E3E96FF7674DF65418C07B1BE98368A2A4F
  30.     23DC4EF2BF1B4F33361370CAE4128F5B86CBE9463411142E5B69A1B586E5DDAD
  31.     0CFEDB2272A1D83799B1597D492D046FF9564180310536DD541EAC1B0951BF29
  32.     432B222092CACA08FF6F950267CBBDC5E0430B6771F1E611914BB9B2D4E84F55
  33.     1C19BF674A45CD4121411B8B6EE845B5CE809C481D8D67D0BDAB47B899418BC0
  34.     779706EFF9F138EC6A89445EB112CBB97A4DA497A06B7A7E90882DDDB6B87CD8
  35.     5F7B4A24D6A15D67415B0034127E76EFBA3DB8235B456BE5929C5B8F535A6667
  36.     5BE981A37B2EE707EFF41E23D08F10D3219EB78047087C90C0D972E5362B6729
  37.     02C8BA34915AA618D98A2688442AB85ABCBFC36BF759E2B911700E9B8D74EB46
  38.     8A36A99FC888743092188C2581D9E8385C6A5D7E3DE704BA387844285FED12E0
  39.     7E02B7AD62398953A9C3426C0ACB84C5988CCD04F4D8347AE2F472263A8672B5
  40.     29BF96F31E602785AC7C285A9A04BF17E0B9DD7215A26ED21D8E040501C6646C
  41.     2690BCF1093E5E5802C24B013850275C6565BDC016B15B4B91C883ABAB5BCEBA
  42.     38B4AC7B9630188B31199B09A4170298D612180E472C04E6FA5163EFCCD77B11
  43.     89E1E318899E17E0FCE4DF6B81E7085491CE20E9660CC6624CC656B3BDDAF2C0
  44.     27F893ED187ACA5D03A8A96842A5DA8288E1CF2D621912F4A377F449511DFC5E
  45.     80AFE1761EEB515A60A61DF04F0C883E91B11893B173FD80B9388178DDCFD16C
  46.     D9B047378268A9EE82212D216545F3C63018D7B62A657691B5C0399736298DF0
  47.     CA6DB8ECEFC3C89481B9095CBC760E1FD2A7852202FC23F01DAE3674E0294936
  48.     5CF174002D5BBA08258504E66F3D03ACE172765105592EC0877AA9654F60661E
  49.     7397DEC6B3BC4D70FC57B6641C0AD37F099F561FC4610B69D7223512DB3C6DF0
  50.     D87D347A0CA664E63BC952759EDB7854DA696AD42E285A2D81F709F0B169CC7E
  51.     FE3ABA69C418C962D6E82202ECB1342FFF4397F059CD411C594E1965516AA31C
  52.     72191ADC9D2853B688E38F29C5293C667E97148B8C64834B6E805739002FDAA8
  53.     1D1FA6C6E63B8C840CB67C9EC09F20DDA324EC4E7DD5B69C84BB155FE79FF126
  54.     F5898FD7136E75A584AA4D3EEA6828A6E5755456F6A2E38E61A4699109211C0D
  55.     8A52E36CE7845B0CA1F7EB33788786044866D76ACB0B497849B6D61FC0BEBB9E
  56.     C4BB76179AB893E1BD9C45918B27F0F2CA0B0C0BD7793A8ED1EBFFC61B933FA0
  57.     9F3E4F65934EDBD0D18CC44542F6A3DA5D8DDABD87D15DB91D8FA82E34DF72DA
  58.     234D7A1C2391317C3170013DCB6151E7742E12DD6F7CA347B3C2EFB62C113749
  59.     059735495941475D58F209926836C996B3C0DA9D1E4E4B79C4CE6D54B68B924A
  60.     94BD9E2DAFF4ED2C5E79FD5F800100550AFA734233AE390000000049454E44AE
  61.     426082
  62.   }
In fact, this is the PNG content encoded in hexadecimal with some header.

The header is:
1754506F727461626C654E6574776F726B4772617068696347070000

Next is the PNG:
89504E470D0A1A0A...
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: Handoko on February 21, 2020, 07:24:09 pm
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.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: lucamar on February 21, 2020, 08:26:31 pm
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 ;) )
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: winni on February 21, 2020, 09:14:08 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
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: circular on February 21, 2020, 09:50:04 pm
The 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)
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: winni on February 21, 2020, 09:58:22 pm
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
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: circular on February 21, 2020, 11:21:03 pm
Indeed

 :D

Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 21, 2020, 11:33:43 pm
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
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: winni on February 22, 2020, 01:54:16 am
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][+][-]
  1. procedure PicFromLFMData;
  2. const fIn = 'pic.data';
  3.       fOut='pic.png';
  4.       hex = ['0'..'9','A'..'F'];
  5. var ch,c1,c2 : char;
  6.     atWork,flipflop: Boolean;
  7.     txt: TextFile;
  8.     f : file of byte;
  9.     len : Integer = -1;
  10.     count : integer;
  11.  
  12.     begin
  13.     assignFile (txt,fIn);
  14.     reset (txt);
  15.     assignFile(f,fOut);
  16.     rewrite(f);
  17.     atWork := false;
  18.     while not eof (txt) do
  19.        begin
  20.        read(txt,ch);
  21.        if ch = '{' then begin atWork := true; flipFlop := false; continue; end;
  22.        if ch = '}' then atWork := false;
  23.        if (ch in hex) and atWork then
  24.          begin
  25.          if not flipFlop then c1 := ch else
  26.             begin
  27.             c2 := ch;
  28.             if len = -1 then
  29.                begin
  30.                len := StrToInt ('$'+c1+c2)+4; // length integer
  31.                count := 0;
  32.                end;
  33.             if count > len then write (f,StrToInt('$'+c1+c2));
  34.             inc(count);
  35.             end;
  36.           flipflop:= not flipflop;
  37.          end; // in
  38.        end;
  39.      closeFile(txt);
  40.      closeFile(f);
  41.      showMessage ('done');
  42.     end;
  43.  
  44.  

Your picture is now in pic.png  - your icon as exspected.

Winni
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 23, 2020, 10:41:35 pm
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][+][-]
  1. procedure PicFromLFMData;
  2. const fIn = 'pic.data';
  3.       fOut='pic.png';
  4.       hex = ['0'..'9','A'..'F'];
  5. var ch,c1,c2 : char;
  6.     atWork,flipflop: Boolean;
  7.     txt: TextFile;
  8.     f : file of byte;
  9.     len : Integer = -1;
  10.     count : integer;
  11.  
  12.     begin
  13.     assignFile (txt,fIn);
  14.     reset (txt);
  15.     assignFile(f,fOut);
  16.     rewrite(f);
  17.     atWork := false;
  18.     while not eof (txt) do
  19.        begin
  20.        read(txt,ch);
  21.        if ch = '{' then begin atWork := true; flipFlop := false; continue; end;
  22.        if ch = '}' then atWork := false;
  23.        if (ch in hex) and atWork then
  24.          begin
  25.          if not flipFlop then c1 := ch else
  26.             begin
  27.             c2 := ch;
  28.             if len = -1 then
  29.                begin
  30.                len := StrToInt ('$'+c1+c2)+4; // length integer
  31.                count := 0;
  32.                end;
  33.             if count > len then write (f,StrToInt('$'+c1+c2));
  34.             inc(count);
  35.             end;
  36.           flipflop:= not flipflop;
  37.          end; // in
  38.        end;
  39.      closeFile(txt);
  40.      closeFile(f);
  41.      showMessage ('done');
  42.     end;
  43.  
  44.  

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.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: circular on February 23, 2020, 11:13:06 pm
You get the data from a string variable instead of file you more or less need to replace
Code: Delphi  [Select][+][-]
  1.     while not eof (txt) do
  2.        begin
  3.        read(txt,ch);
by
Code: Delphi  [Select][+][-]
  1.     for i := 1 to length(strData) do
  2.        begin
  3.        ch := strData[i];
where strData is your string variable.

And remove the txt variable and what refers to it.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 24, 2020, 12:32:04 am
You get the data from a string variable instead of file you more or less need to replace
Code: Delphi  [Select][+][-]
  1.     while not eof (txt) do
  2.        begin
  3.        read(txt,ch);
by
Code: Delphi  [Select][+][-]
  1.     for i := 1 to length(strData) do
  2.        begin
  3.        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][+][-]
  1. 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][+][-]
  1. stream.Write(f, sizeOf(StrToInt('$'+c1+c2)));
  2. stream.Position:= 0;
  3. png.LoadFromStream(stream);
  4. frmIndex.Image1.Picture.PNG.Assign(png);

Thnx again :)
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: Handoko on February 24, 2020, 02:19:24 pm
It seems you have problem using my functions. Here I show how to export image to a text file.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Image1: TImage;
  17.     procedure Button1Click(Sender: TObject);
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,
  26.   FileName: string); forward;
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. var
  34.   aStream: TMemoryStream;
  35. begin
  36.   aStream := TMemoryStream.Create;
  37.   Image1.Picture.SaveToStream(aStream);
  38.   StreamToHexStringFile(aStream, 'ImageData', 'IMG.TXT');
  39.   aStream.Free;
  40.  
  41.   ShowMessage('The image has been exported to IMG.TXT' +LineEnding+
  42.     'You can use it in your Pascal code by copy/pasting the text' +LineEnding+
  43.     'directly or using the compiler directive {$INCLUDE filename}.');
  44. end;
  45.  
  46. //----------------------------------------------------------------------
  47.  
  48. procedure HexStringToStream(const Input: string; Output: TMemoryStream;
  49.   OutputReturn: Boolean);
  50. var
  51.   Bookmark:   Int64;
  52.   Buffer:     array of Byte;
  53.   ResultSize: Integer;
  54.   i:          Integer;
  55. begin
  56.   ResultSize := Input.Length div 2;
  57.   SetLength(Buffer, ResultSize);
  58.   HexToBin(PChar(Input), PChar(Buffer), ResultSize);
  59.   Bookmark := Output.Position;
  60.   for i := 0 to (ResultSize-1) do
  61.     Output.WriteByte(Buffer[i]);
  62.   if OutputReturn then
  63.     Output.Position := Bookmark;
  64. end;
  65.  
  66. procedure StreamToHexStringList(Input: TMemoryStream; Output: TStringList);
  67. var
  68.   Buffer: array[0..31] of Byte;
  69.   Remain: Integer;
  70.   Todo:   Integer;
  71.   S:      string;
  72.   i:      Integer;
  73. begin
  74.   Input.Seek(0, soBeginning);
  75.   Remain := Input.Size;
  76.   while (Remain > 0) do
  77.   begin
  78.     Todo := 32;
  79.     if (Remain < 32) then
  80.       Todo := Remain;
  81.     Input.ReadBuffer(Buffer, Todo);
  82.     S := '';
  83.     for i := 0 to (Todo- 1) do
  84.       S := S + IntToHex(Buffer[i], 2);
  85.     Output.Add(S);
  86.     Remain := Remain - Todo;
  87.   end;
  88. end;
  89.  
  90. procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,
  91.   FileName: string);
  92. var
  93.   Buffer: TStringList;
  94.   S:      string;
  95.   i:      Integer;
  96. begin
  97.   Buffer := TStringList.Create;
  98.   StreamToHexStringList(Input, Buffer);
  99.   with Buffer do
  100.   begin
  101.     for i := 0 to (Count-1) do
  102.     begin
  103.       S := '    ' + '''' + Strings[i] + '''';
  104.       case (i < Count-1) of
  105.         True:  S := S + '+';
  106.         False: S := S + ';';
  107.       end;
  108.       Buffer[i] := S;
  109.     end;
  110.     if (Count >= 0) then
  111.     begin
  112.       Insert(0, '  ' + ConstName + ' = ');
  113.       Insert(0, 'const');
  114.       SaveToFile(FileName);
  115.     end;
  116.     Free;
  117.   end;
  118. end;
  119.  
  120. end.

There are 3 functions, I let you to figure out yourself how to use the others.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 24, 2020, 04:22:22 pm
It seems you have problem using my functions. Here I show how to export image to a text file.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Image1: TImage;
  17.     procedure Button1Click(Sender: TObject);
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,
  26.   FileName: string); forward;
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. var
  34.   aStream: TMemoryStream;
  35. begin
  36.   aStream := TMemoryStream.Create;
  37.   Image1.Picture.SaveToStream(aStream);
  38.   StreamToHexStringFile(aStream, 'ImageData', 'IMG.TXT');
  39.   aStream.Free;
  40.  
  41.   ShowMessage('The image has been exported to IMG.TXT' +LineEnding+
  42.     'You can use it in your Pascal code by copy/pasting the text' +LineEnding+
  43.     'directly or using the compiler directive {$INCLUDE filename}.');
  44. end;
  45.  
  46. //----------------------------------------------------------------------
  47.  
  48. procedure HexStringToStream(const Input: string; Output: TMemoryStream;
  49.   OutputReturn: Boolean);
  50. var
  51.   Bookmark:   Int64;
  52.   Buffer:     array of Byte;
  53.   ResultSize: Integer;
  54.   i:          Integer;
  55. begin
  56.   ResultSize := Input.Length div 2;
  57.   SetLength(Buffer, ResultSize);
  58.   HexToBin(PChar(Input), PChar(Buffer), ResultSize);
  59.   Bookmark := Output.Position;
  60.   for i := 0 to (ResultSize-1) do
  61.     Output.WriteByte(Buffer[i]);
  62.   if OutputReturn then
  63.     Output.Position := Bookmark;
  64. end;
  65.  
  66. procedure StreamToHexStringList(Input: TMemoryStream; Output: TStringList);
  67. var
  68.   Buffer: array[0..31] of Byte;
  69.   Remain: Integer;
  70.   Todo:   Integer;
  71.   S:      string;
  72.   i:      Integer;
  73. begin
  74.   Input.Seek(0, soBeginning);
  75.   Remain := Input.Size;
  76.   while (Remain > 0) do
  77.   begin
  78.     Todo := 32;
  79.     if (Remain < 32) then
  80.       Todo := Remain;
  81.     Input.ReadBuffer(Buffer, Todo);
  82.     S := '';
  83.     for i := 0 to (Todo- 1) do
  84.       S := S + IntToHex(Buffer[i], 2);
  85.     Output.Add(S);
  86.     Remain := Remain - Todo;
  87.   end;
  88. end;
  89.  
  90. procedure StreamToHexStringFile(Input: TMemoryStream; const ConstName,
  91.   FileName: string);
  92. var
  93.   Buffer: TStringList;
  94.   S:      string;
  95.   i:      Integer;
  96. begin
  97.   Buffer := TStringList.Create;
  98.   StreamToHexStringList(Input, Buffer);
  99.   with Buffer do
  100.   begin
  101.     for i := 0 to (Count-1) do
  102.     begin
  103.       S := '    ' + '''' + Strings[i] + '''';
  104.       case (i < Count-1) of
  105.         True:  S := S + '+';
  106.         False: S := S + ';';
  107.       end;
  108.       Buffer[i] := S;
  109.     end;
  110.     if (Count >= 0) then
  111.     begin
  112.       Insert(0, '  ' + ConstName + ' = ');
  113.       Insert(0, 'const');
  114.       SaveToFile(FileName);
  115.     end;
  116.     Free;
  117.   end;
  118. end;
  119.  
  120. 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.
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: circular on February 24, 2020, 07:36:36 pm
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.
I think each person is in a better position to know if they understood my dear.  :P
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: winni on February 24, 2020, 10:55:21 pm
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
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 25, 2020, 05:07:38 am
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][+][-]
  1. Var
  2.   picData : String;
  3.  
  4. Begin
  5.  
  6. picData := '{' +
  7.     '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.
   
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: PascalDragon on February 25, 2020, 09:41:44 am
Here is how TPicture reads the data from the LFM stream:

Code: Pascal  [Select][+][-]
  1. procedure TPicture.ReadData(Stream: TStream);
  2. var
  3.   GraphicClassName: Shortstring;
  4.   NewGraphic: TGraphic;
  5.   GraphicClass: TGraphicClass;
  6.   ok: boolean;
  7. begin
  8.   Stream.Read(GraphicClassName[0], 1);
  9.   Stream.Read(GraphicClassName[1], length(GraphicClassName));
  10.   GraphicClass := GetPicFileFormats.FindClassName(GraphicClassName);
  11.   NewGraphic := nil;
  12.   if GraphicClass <> nil then begin
  13.     NewGraphic := GraphicClass.Create;
  14.     ok:=false;
  15.     try
  16.       NewGraphic.ReadData(Stream);
  17.       ok:=true;
  18.     finally
  19.       if not ok then NewGraphic.Free;
  20.     end;
  21.   end;
  22.   FGraphic.Free;
  23.   FGraphic := NewGraphic;
  24.   if NewGraphic <> nil then begin
  25.     NewGraphic.OnChange := @Changed;
  26.     NewGraphic.OnProgress := @Progress;
  27.   end;
  28.   Changed(Self);
  29. 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][+][-]
  1. var
  2.   picdata: String = '{' +
  3.     '17545 …';
  4.   s: TStringStream;
  5.   GraphicClassName: String;
  6.   NewGraphic: TGraphic;
  7.   GraphicClass: TGraphicClass;
  8.   ok: Boolean;
  9.   pic: TPicture;
  10. begin
  11.   s := TStringStream.Create(picdata);
  12.   try
  13.     s.Read(GraphicClassName[0], 1);
  14.     s.Read(GraphicClassName[1], Length(GraphicClassName));
  15.     if GraphicClassName = 'TPortableNetworkGraphic' then
  16.       GraphicClass := TPortableNetworkGraphic
  17.     else
  18.       raise Exception.CreateFmt('Unknown graphic class: %s', [GraphicClassName]);
  19.     NewGraphic := GraphicClass.Create;
  20.     ok := False;
  21.     try
  22.       NewGraphic.ReadData(s);
  23.       ok := True;
  24.     finally
  25.       if not ok then
  26.         NewGraphic.Free;
  27.     end;
  28.     pic := TPicture.Create(Nil);
  29.     try
  30.       pic.Graphic := NewGraphic;
  31.       YourButton.Glyph := pic.Bitmap;
  32.     finally
  33.       pic.Free;
  34.     end;
  35.   finally
  36.     s.Free;
  37.   end;
  38. end;
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: bytebites on February 25, 2020, 01:03:47 pm
Combining from previous replies one reply more.
Code: Pascal  [Select][+][-]
  1.  
  2. picData :=  '1754506F727461 ...';
  3.  
  4. function convert(picData: string): TPicture;
  5. var
  6.   stream: TStringStream;
  7.   ch: PChar;
  8.   i, num: integer;
  9.   Picture: TPicture;
  10.   GraphicClassName: ShortString;
  11.  
  12.   function tohex(p: PChar): byte;
  13.   begin
  14.     case p^ of
  15.       '0'..'9': Result := Ord(p^) - 48;
  16.       'A'..'F': Result := Ord(p^) - 55;
  17.       else raise Exception.CreateFmt('Unexpected char: %s', [p^]);
  18.     end;
  19.   end;
  20.  
  21. begin
  22.   i := length(picData);
  23.   ch := @picdata[1];
  24.   stream := tstringstream.Create;
  25.   while i > 0 do
  26.   begin
  27.     num := tohex(ch) * 16 + tohex(ch + 1);
  28.     stream.Write(num, 1);
  29.     ch := ch + 2;
  30.     i := i - 2;
  31.   end;
  32.   stream.position := 0;
  33.   stream.Read(GraphicClassName[0], 1);
  34.   stream.Read(GraphicClassName[1], Length(GraphicClassName));
  35.   if GraphicClassName <> 'TPortableNetworkGraphic' then
  36.     raise Exception.CreateFmt('Unknown graphic class: %s', [GraphicClassName]);
  37.   stream.Read(i, 4);
  38.   // assert(stream.Size-stream.Position=i,'size error');
  39.   Picture := TPicture.Create;
  40.   Picture.LoadFromStream(stream);
  41.   Result := Picture;
  42.   stream.Free;
  43. end;
  44.  
  45. procedure TForm1.Button1Click(Sender: TObject);
  46. var
  47.   b: TPicture;
  48. begin
  49.   b := convert(picData);
  50.   image1.Picture := b;
  51.   BitBtn1.Glyph := b.Bitmap;
  52.   b.Free;
  53. end;                                
  54.  
  55.  
Title: Re: Convert glyph data and assign it to TBitBtn
Post by: SaraT on February 25, 2020, 04:28:22 pm
Many thanks guys
It worked finally :)

Happy coding
Title: Re: SOLVED: Convert glyph data and assign it to TBitBtn
Post by: AsleyCruz on February 25, 2020, 08:51:04 pm
Amazing!
This would be useful to load PNG into custom components.
TinyPortal © 2005-2018