delphi 如何将Bitmap位图与base64字符串相互转换


本文整理自网络,侵删。

 
by 菩提树下的杨过 http://yjmyzz.cnblogs.com/

///将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;

相关阅读 >>

Delphi中使用ado连接带密码的access

Delphi tapplication大全

Delphi 颜色转换函数: 从 Delphi 到 html

Delphi 获取外部程序句柄与发送消息

Delphi 判断timage是否为空及注意事项

Delphi禁止用户切换任务

为什么编程是独一无二的职业

Delphi 深入了解unigui hyperserver

Delphi 新建一个txt文档函数

Delphi 15位身份证号码转18位身份证号码

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...