[DUG] XML data to image problem
Jolyon Smith
jsmith at deltics.co.nz
Thu Apr 21 11:00:34 NZST 2011
Create a test case that you know should work... i.e. take a known jpeg file,
encode as base 64, embed in an XML and run it thru your code.
If you don't get a valid JPEG file at the end, then you know the code has a
problem - fix it so that you do get a valid JPEG then run it on your real
case again.
If you still don't get a valid JPEG file from your real data then you at
least now know the code is sound and therefore that one or both of your
assumptions about the data is wrong. Either it isn't a JPEG or it isn't
base64 encoded or it's neither base64 nor a JPEG.
In any event, assumptions are *always* dangerous, but I'm guessing you knew
that already. :)
-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Robert Martin
Sent: Thursday, 21 April 2011 10:40
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] XML data to image problem
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
_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe
More information about the Delphi
mailing list