Using Delphi 10.2 I right-click on a TClientDataSet and choose 'Save to MyBase Xml UTF-8 table.' I now have an XML file with this format:
<ROW NAME="Angel Fish" SIZE="2" WEIGHT="2" AREA="Computer Aquariums" BMP="AQAAAfY+AABCTfY+AAAAAAAAdgAAACgAAADIAAAAoAAAAAEA ...
The BMP field is defined as:
<FIELD attrname="BMP" fieldtype="bin.hex" SUBTYPE="TypedBinary" WIDTH="1"/>
I'm trying to convert what I believe to be a Base64 string representation of a binary bitmap file into a picture. So far I've got this:
uses
XMLDoc, Vcl.ComCtrls, XMLIntf, IdCoder, IdCoderMIME, IdGlobal,
Vcl.ExtCtrls;
procedure TForm2.Button1Click(Sender: TObject);
var Doc:TXMLDocument;
First:IXMLNode;
Str:String;
Bytes: TIdBytes;
Pic:TPicture;
Stream:TMemoryStream;
Writer: TBinaryWriter;
begin
Doc:=TXMLDocument.Create(Self);
Doc.FileName:='D:\temp\ClientDataSet2.xml';
Doc.Active:=true;
First:=Doc.DocumentElement.ChildNodes['ROWDATA'].ChildNodes.First;
Str:=First.Attributes['BMP'];
Bytes:=TIdDecoderMIME.DecodeBytes(Str);
Stream:=TMemoryStream.Create;
Writer:=TBinaryWriter.Create(Stream);
Writer.Write(TBytes(Bytes));
Stream.Position:=0;
Pic:=TPicture.Create;
Pic.LoadFromStream(Stream);
Image1.Picture:=Pic;
RichEdit1.Text:=Str;
end;
However, TPicture.LoadFromStream throws this exception:
First chance exception at $74DCCBB2. Exception class EInvalidGraphic with message 'Unsupported stream format'.
Could anybody please tell me what I'm doing wrong? Many thanks.