EncodeBase64和TIDEncoderMime.EncodeStream中的不同字符串长度

时间:2013-10-25 13:19:41

标签: delphi

在下面的代码片段中,method1使showmessage显示10048,而方法2和3显示9792.哪种方法提供正确的编码以在XML节点中使用?磁盘上的文件大小为7343.谢谢

DrawingField: AnsiString;
PicStream := TMemoryStream.Create;
encoder := TidEncoderMIME.Create(nil);
StringStream := TStringStream.Create('');
try
  Image1.Picture.LoadFromFile('Ryan.jpg');
  Image1.Picture.Graphic.SaveToStream(PicStream);

  {$ifdef METHOD1}
  DrawingField := EncodeBase64(PicStream.Memory, PicStream.Size);
  {$endif}
  {$ifdef METHOD2}
  PicStream.Position := 0;
  encoder.EncodeStream(PicStream, StringStream);
  DrawingField := StringStream.DataString;
  {$endif}
  {$ifdef METHOD3}
  PicStream.Position := 0;
  DrawingField := encoder.EncodeStream(PicStream, PicStream.Size);
  // SetString(DrawingField, PAnsiChar(PicStream.Memory), PicStream.Size);
  {$endif}

  ShowMessage(IntToStr(Length(DrawingField))); // 1 = 10048 2/3 = 9792
finally
  encoder.Free;
  PicStream.Free;
  StringStream.Free;
end;

0 个答案:

没有答案