Base 64 Conversion in PNG

0

I'm migrating from Delphi 2007 to Berlin and a code that worked in 2007 does not work in Berlin. I use the following code to generate a PNG from base64 text, but it is returning the error:

  

no mapping for the unicode character exists in the target multibyte code page

This error occurs on line stream:= TStringStream.Create(EncdDecd.DecodeString(sTemp)); I'd like to know how to do the correct conversion in Berlin. To help follow the low link with PNG in base 64 and the method with excerpt that does the conversion.

base64.txt

procedure TForm1.LoadPng;
var
  sTemp:  string;
  slTemp: TStringList;

  stream: TStringStream;
  png: TPngObject;
begin
  slTemp := TStringList.Create;
  slTemp.LoadFromFile('C:\base64.txt');
  sTemp:= slTemp.Text;

  if sTemp = '' then
    Exit;

  stream:= TStringStream.Create(EncdDecd.DecodeString(sTemp));
  stream.Position:= 0;

  png:= TPngObject.Create;
  png.Create.LoadFromStream(stream);
  Image1.Picture.Assign(png);
end;
    
asked by anonymous 19.05.2017 / 22:00

2 answers

0

For many years I have not seen anything in Delphi, but looking at your code above I would suggest that instead of declaring sTemp as string , declare as UnicodeString or AnsiString and test again.

    
19.05.2017 / 22:45
0

Finding more I found a new component that does this work properly in Delphi from XE and searching for this component I found a solution in the intersseational stackoverflow (I do not know why it did not appear in my initial search) follow the link to the question: link

    
21.05.2017 / 13:47