在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
先引用delphi自带的单元
uses EncdDecd; 然后就可以使用下面二个函数了: ///将Bitmap位图转化为base64字符串
function BitmapToString(img:TBitmap):string ; var ms:TMemoryStream; ss:TStringStream; s:string; begin ms := TMemoryStream.Create; img.SaveToStream(ms); ss := TStringStream.Create(''); ms.Position:=0; EncodeStream(ms,ss);//将内存流编码为base64字符流 s:=ss.DataString; ms.Free; ss.Free; result:=s; end; ///将base64字符串转化为Bitmap位图 function StringToBitmap(imgStr:string):TBitmap; var ss:TStringStream; ms:TMemoryStream; bitmap:TBitmap; begin ss := TStringStream.Create(imgStr); ms := TMemoryStream.Create; DecodeStream(ss,ms);//将base64字符流还原为内存流 ms.Position:=0; bitmap := TBitmap.Create; bitmap.LoadFromStream(ms); ss.Free; ms.Free; result :=bitmap; end; uses EncdDecd; 然后就可以使用下面二个函数了: ///将Bitmap位图转化为base64字符串
function BitmapToString(img:TBitmap):string ; var ms:TMemoryStream; ss:TStringStream; s:string; begin ms := TMemoryStream.Create; img.SaveToStream(ms); ss := TStringStream.Create(''); ms.Position:=0; EncodeStream(ms,ss);//将内存流编码为base64字符流 s:=ss.DataString; ms.Free; ss.Free; result:=s; end; ///将base64字符串转化为Bitmap位图 function StringToBitmap(imgStr:string):TBitmap; var ss:TStringStream; ms:TMemoryStream; bitmap:TBitmap; begin ss := TStringStream.Create(imgStr); ms := TMemoryStream.Create; DecodeStream(ss,ms);//将base64字符流还原为内存流 ms.Position:=0; bitmap := TBitmap.Create; bitmap.LoadFromStream(ms); ss.Free; ms.Free; result :=bitmap; end; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论