将base64转换为图像|不工作|扑

发布于 2025-01-27 01:27:51 字数 597 浏览 6 评论 0原文

因此,我想做一个简单的事情,但由于某些原因,它无法正常工作。我从服务器中获得了一个基本64字符串,我需要将其转换为图像。当我将其放在网站中时,例如 base64guru ,它起作用。但是,我无法在Flutter应用程序中做同样的事情。

这是我的代码的样子:

final decodedBytes = base64Decode(base64String);
var file = File("userPdf.png");
file.writeAsBytesSync(decodedBytes);
return Image.file(file);

执行此操作时,我会发现一个错误说明:

filesystemexception:无法打开文件,path ='userpdf.png(OS错误: 仅读取文件系统,errno = 30)

知道我在做什么错以及如何做到这一点?任何帮助将不胜感激。

So, I want to do a simple thing but for some reasons it is not working. I get a base64 string from the server which I need to convert to an image. When I put that retrieved in the websites like base64guru, it works. However I'm unable to do the same in my flutter app.

Here's what my code looks like:

final decodedBytes = base64Decode(base64String);
var file = File("userPdf.png");
file.writeAsBytesSync(decodedBytes);
return Image.file(file);

When this is executed, I get an error stating :

FileSystemException: Cannot open file, path = 'userPdf.png (OS Error:
Read-only file system, errno = 30)

Any idea what I'm doing wrong and how I can do this ?? Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恋你朝朝暮暮 2025-02-03 01:27:51

好吧,当我在容器中包装sfpdfviewer.memory(bytes)时,这得到了解决。不过,不确定为什么没有容器就无法正常工作。

整个解决方案:

Uint8List bytes = base64.decode(pdf);
return Container(
  child: SfPdfViewer.memory(bytes),
);

使用的软件包:syncfusion_flutter_pdfviewer

Well, this got resolved when I wrapped SfPdfViewer.memory(bytes) inside a Container. Though, not sure why it wasn't working without a Container.

The whole solution:

Uint8List bytes = base64.decode(pdf);
return Container(
  child: SfPdfViewer.memory(bytes),
);

Package used : syncfusion_flutter_pdfviewer

守不住的情 2025-02-03 01:27:51

有一个简单的方法

Image.memory(base64Decode(base64String));

There is a simple way

Image.memory(base64Decode(base64String));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文