I am trying to decode a base64 encoded EMF image from an XML document in my application and display it on the screen, however it never appears.
If I copy / paste data from an XML document into Notepad ++ and use a parameter Base64 Decodeand save the file as .emfit opens perfectly in mspaint. So I think the problem is how I decode it.
I tried the following decoding methods described in these articles:
How to encode / decode Base 64 string
http://www.swissdelphicenter.ch/torry/showcode.php?id=1223
I also tried the class to TIdDecoderMIMEno avail.
Does anyone know the most reliable way to decode base64 string encoding 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 does this not work above, but copying raw data into Notepad ++ and decoding and saving while working .emf?
James source
share