Delphi 7 Glyph.Data Hex To Data URI
Solution 1:
Perform the following to extract a Windows bitmap from this Delphi form file:
- Read the hex string.
- Convert the hex string to binary (a byte array). If using Delphi you can do this with
HexToBin
from theClasses
unit. If using some other language then you will have to use the appropriate function to convert from hex to binary. - Remove the first 4 bytes from the byte array. These bytes that are removed contain the length of the remaining bytes.
- Save these bytes to a file.
What you have saved is a Windows bitmap file. You'll likely want to convert to a web friendly format such as PNG, but I presume you already have tools to do that.
Finally, you'll need to encode that PNG file as base64 and thus form a data URI. Again, I am presuming that you know how to do that.
In the example you present you can also see the NumGlyphs
property indicates that the glyph contains two images. You might want to split the extracted bitmap into multiple images.
Solution 2:
Excuse me in advance for my very bad english.
There are two options.
1) working with a file text without blank spaces use a algorithm/function that use readln. I post this approch below
2) I have realized some functions that work perfectly
function HexaBmp(const aSource, aDest: String): Integer; // done function BmpHexa(const aSource, aDest: String): Integer; // work done function Bin2Bin(const aSource, aDest: String): Integer; // work done (binary in binary text) function Txt2Bin(const aSource, aDest: String): Integer; // (binary text in binary) working in progress...
This functions uses this subfunctions...
procedure Reading; begin BlockRead(F1, PFBuf^, SIZEFB, BytesIng) end;
procedure Writing; begin BlockWrite(F2, BLWR, Z, BytesOut) end;
but for copyright reasons don't post this (i dont'understend if i'll be owner of these) Sorry for this... I can't explain more. It's more plus complicated. a sofisticate and robust algorithm is necessary but is very fast.
But don't worry because you can use this my little program below for the scope that use the first approach.
program HexaToBmp;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
const
CHX: array ['0'..'F'] of Byte = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15);
var
FtoW: TextFile;
FtoR: TextFile;
WFile: String; // name of write file
Buff: String; // string buffer of read file
vS: String; // calc string
FNY: Word; // final Y
M: Word; // prior of Y
Y: Word; // in loop while read index
procedure TextSeek(var aFtx: Text; POS: Cardinal);
begin
with TTextRec(aFtx) do
begin
BufPos:= 0;
BufEnd:= 0;
SetFilePointer(Handle, POS, nil, FILE_BEGIN)
end
end;
begin
WFile:= StringReplace(ParamStr(1), ExtractFileExt(ParamStr(1)), 'WF', []) + '.bmp';
AssignFile(FtoR, ParamStr(1));
AssignFile(FtoW, WFile);
vS:= '';
try
Reset(FtoR);
ReWrite(FtoW);
TextSeek(FtoR, 8); // position after the first 8 byte
while not EOF(FtoR) do
begin
Readln(FtoR, Buff);
FNY:= Length(Buff) + 1;
M:= 1;
Y:= 2;
while Y < FNY do
begin
if Buff[Y] = #$A then // new line jump
begin
Write(FtoW, vS); // writing current line
vS:= '';
Y:= Y + 1 // jump correct index
end
else
vS:= vS + Chr(16 * CHX[Buff[M]] + CHX[Buff[Y]]); // calc bin value
M:= Y + 1; // increment the variable values
Y:= M + 1
end
end;
Write(FtoW, vS)
finally
CloseFile(FtoR);
CloseFile(FtoW)
end
end.
`
Post a Comment for "Delphi 7 Glyph.Data Hex To Data URI"