频道分类

delphi 将base64字符串转化为Jpeg图片

作者:admin 来源: 日期:2020/3/29 22:25:57 人气: 标签:

 
uses jpeg,EncdDecd;


function Base64StringToJpeg(ImgStr:string):TJPEGImage;
var ss:TStringStream;
    ms:TMemoryStream;
    jpg:TJPEGImage;
begin
  try
    ss := TStringStream.Create(imgStr);
    ms := TMemoryStream.Create;
    DecodeStream(ss,ms);//将base64字符流还原为内存流
    ms.Position:=0;
    jpg := TJPEGImage.Create;
    jpg.LoadFromStream(ms);
    ss.Free;
    ms.Free;
    result :=jpg;
  except
  end;
end;