网上找到的用xml传输图片

前端之家收集整理的这篇文章主要介绍了网上找到的用xml传输图片前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

先记下来,试过后如果可用,就保留下来。


用到ZLIB和base64

ProcedureStrToBmpStream(v:OleVariant;VarStream:TMemoryStream);
Var
Str:String;
MS1:TStringStream;
MS2:TMemoryStream;
Begin
IfVarIsNull(v)ThenExit;
Str:=VarToStr(v);
IfStr=''ThenExit;
MS1:=TStringStream.Create(Str);
MS2:=TMemoryStream.Create;
Base64DeCodeStream(MS1,MS2);
MS2.Position:=0;
ZDecompressStream(MS2,Stream);
Stream.Position:=0;
FreeAndNil(MS2);
FreeAndNil(MS1);
End;

FunctionBmpStreamToStr(Stream:TMemoryStream):String;
MS1:TMemoryStream;
MS2:TStringStream;
MS1:=TMemoryStream.Create;
MS2:=TStringStream.Create('');
ZCompressStream(Stream,MS1,zcMax);
MS1.Position:=0;
Base64EnCodeStream(MS1,245)">Result:=MS2.DataString;
ms:=TMemoryStream.Create;
StrToBmpStream('这里是BASE64编码的字符',ms);
image1.Picture.Bitmap.LoadFromStream(ms);
MS.Clear;
image1.Picture.Bitmap.SaveToStream(MS);
str:=BmpStreamToStr(MS)
将字符保存到XML即可

猜你在找的XML相关文章