[DUG] XML data to image problem
Robert Martin
rob at chreos.co.nz
Thu Apr 21 10:39:47 NZST 2011
Hi
I am getting image data from an XML file. The author has not provided
information as to encoding or file type but I am assuming base64 and
Jpg. I have the following code which does produce a file but it appears
corrupt.
if (aNode <> nil)
and (ANode.NodeValue <> Null) then begin
//Save file
FileName := TempDir + 'Preview.jpg';
DeleteFile(FileName);
FileStream := TFileStream.Create(FileName, fmCreate);
try
//Assume node is Base64 encoded binary data
base64Decoder := TIdDecoderMIME.Create(Self);
try
ImageData :=
base64Decoder.DecodeString(ANode.NodeValue)
finally
base64Decoder.Free;
end;
FileStream.Position := 0;
FileStream.Write(Pointer(ImageData)^,
Length(ImageData));
finally
FileStream.Free;
end;
end
I have tried changing the file extension but it does not open. I have
also tried no base 64 decode but that also fails to produce a valid
file. Can anyone see anything obviously wrong before I go back to the
source for further information (they are in the UK so its a day turn
around AND they are really unhelpful).
Thanks
Rob
More information about the Delphi
mailing list