Recent

Author Topic: Getting image data  (Read 374 times)

AsleyCruz

  • Full Member
  • ***
  • Posts: 118
    • Graphic and web designer
Getting image data
« on: September 02, 2025, 06:47:30 pm »
Hi coders,
Can you please give me a function to get the image data from a TSpeedButton control?

Here is an idea of what I'm trying to get in string from "Glyph" property from TSpeedButton:

Function result:
Code: Pascal  [Select][+][-]
  1.   Glyph.Data = {
  2.     36100000424D3610000000000000360000002800000020000000200000000100
  3.     2000000000000010000064000000640000000000000000000000000000000000
  4.     0000000000000000000000000000000000000000000000000000000000000000
  5.     ...
  6.   }

Thanks in advance!
Graphic & web designer

wp

  • Hero Member
  • *****
  • Posts: 13222
Re: Getting image data
« Reply #1 on: September 02, 2025, 07:44:18 pm »
The string consists of the hex string representation of byte values, i.e. take groups of always two digits and convert that to a byte, put all bytes into an array and write that to a stream. The stream finally can be opened by a TPicture. But note that there is a 4-byte header which must be ignored. See the sequence '424D' in the first line? This corresponds to 'BM' which is the signature of a bmp file.
Code: Pascal  [Select][+][-]
  1. procedure PictureFromGlyphData(DataStr: String; APicture: TPicture);
  2. var
  3.   b: TBytes = nil;
  4.   i, j, n: Integer;
  5.   s: String[3] = '$__';
  6.   stream: TStream;
  7. begin
  8.   i := 1;
  9.   j := 0;
  10.   n := Length(DataStr);
  11.   SetLength(b, n div 2);
  12.   while i < n do
  13.   begin
  14.     s[2] := char(DataStr[i]);
  15.     s[3] := char(DataStr[i+1]);
  16.     b[j] := StrToInt(s);
  17.     inc(j);
  18.     inc(i, 2);
  19.   end;
  20.  
  21.   stream := TMemoryStream.Create;
  22.   try
  23.     stream.Write(b[4], Length(b)-4);    // Skip 4-byte header
  24.     stream.Position := 0;
  25.     APicture.LoadFromStream(stream);
  26.   finally
  27.     stream.Free;
  28.   end;
  29. end;  
« Last Edit: September 02, 2025, 07:48:20 pm by wp »

AsleyCruz

  • Full Member
  • ***
  • Posts: 118
    • Graphic and web designer
Re: Getting image data
« Reply #2 on: September 02, 2025, 08:06:44 pm »
The string consists of the hex...

Hi, this works perfect in reverse converting from Image data to TPicture
but, let me ask you about converting TPicture to image data.

Thanks for your time.

I have the SpeedButton1 and want to convert the glyph data into string. i.e:

Code: Pascal  [Select][+][-]
  1. Glyph.Data = {
  2.   361000...
  3. }
Graphic & web designer

 

TinyPortal © 2005-2018