解码base64图片字符串提示错误:no mapping for the unicode character exists in the target mult

aidpoint20126 2020-11-26 04:58:28
base64的图片字符串,我用xe10的EncdDecd.DecodeString解码提示错误:

no mapping for the unicode character exists in the target multi-byte code page

各位大侠请指教???
解码后我好还原为图片
...全文
1403 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueStorm 2020-12-02
  • 打赏
  • 举报
回复
如果你把base64字符串贴出来,马上就可以判定原因。
tanqth 2020-11-27
  • 打赏
  • 举报
回复
就你说这个DecodeString,也应该是解码BASE64为字符串,图片数据不可能是字符串的。 解决方式: 引用system.netencoding单元 使用下面这条解码 Tnetencoding.Base64.Decode(Input, Output); Input为需要解码的流(需要先把你的BASE64的字符串转换为输入流) Output为最后解码出来的流 Output就是你需要的图片数据了,可以直接保存为文件。
天行归来 2020-11-26
  • 打赏
  • 举报
回复
我用 Delphi2010 封装了解码函数,XE10没试过。


class function Base64DecodeImageFile(fileName: string; encodeStr: AnsiString): boolean;
var
  bts: TBytes;
  ms :TMemoryStream;
  decoder: TIdDeCoderMIME;
begin
  decoder := TIdDeCoderMIME.Create(nil);
  ms := TMemoryStream.Create();
  try
    bts := decoder.DecodeBytes(encodeStr);
    ms.Write(bts[0],Length(bts));
    ms.SaveToFile(fileName);
    result := true;
  except
    result := false;
  end;
  decoder.Free;
  ms.Free;
end;

1,185

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧