I am trying to decode a base64 encoded EMF image from an XML document in my application and render it on screen, however, it never seems to appear.
If I copy/paste the data from the XML document into Notepad++ and use the Base64 Decode
option and save the file as a .emf
it opens fine in mspaint. So I think the issue is how I am decoding it.
I have tried the following decode methods described in these articles:
How to encode / decode Base 64 string
http://www.swissdelphicenter.ch/torry/showcode.php?id=1223
I have also tried the TIdDecoderMIME
class to no avail.
Does anyone know the most reliable way of decoding a base64 encoded string from XML?
Example
procedure TXmlSerializer.SaveImageFromString(const AValue: string);
var
StrStream: TStringStream;
Decoder: TIdDecoderMIME;
begin
// AValue is base64 encoded string from XML doc
Decoder := TIdDecoderMIME.Create(nil);
try
StrStream := TStringStream.Create(Decoder.DecodeString(AValue));
try
StrStream.SaveToFile('MyPath\Image.emf');
finally
StrStream.Free;
end;
finally
Decoder.Free;
end;
end;
Why is it the above doesn't work but copying the raw data into Notepad++ and decoding & saving as .emf
works?