How to convert hexa data to picture with delphi XE? (in this case, i want to show a picture that I take from camera to my GUI)
How to convert hexa data to picture with delphi XE? (in this case, i want to show a picture that I take from camera to my GUI)
Thanks!
Thanks!
Convert the hex string to binary using HexToBin, and then load that binary into the appropriate image class.
ReplyDeleteYou are probably doing something wrong if you have the data as a hex string. Don't convert the raw binary data into a hex string, only so that you can subsequently convert it back to binary. Work entirely with the raw binary data.
procedure foo(const AFileName: String);
ReplyDeletevar
Strings: TStrings;
Line: String;
Buffer: TBytes;
off: Integer;
BytesReaded: Integer;
Stream: TStream;
begin
Strings:=TStringList.Create;
Strings.LoadFromFile(AFileName);
off:=0;
SetLength(Buffer,4096);
for Line in Strings do
begin
if Length(Line) SetLength(Buffer,Length(Buffer)+4096);
BytesReaded:=HexToBin(pChar(Line),pAnsiChar(@BUffer[off]),Length(Buffer)-off);
Inc(off,BytesReaded);
end;
Strings.Free;
Stream:=TFile.Create(TPath.ChangeExtension(AFileName,'.bmp')); //your data is a windows bitmap
Stream.Write(Buffer,off);
Stream.Free;
end;