首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Uint8List图像转换为.jpg / .png?

问如何将Uint8List图像转换为.jpg / .png?
EN

Stack Overflow用户
提问于 2021-03-04 03:23:37
回答 2查看 186关注 0票数 0

我正在使用flutter_inappwebview来截取网页的截图。截图为Uint8List格式。我想把它改成File,这样我就可以把它保存在我的服务器上。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-04 15:28:53

代码语言:javascript
复制
getApplicationDocumentsDirectory() is from path_provider package.

onPressed: () async {
          final result = await webView.takeScreenshot();
          final directory = (await getApplicationDocumentsDirectory()).path; // to get path of the file
          String fileName = DateTime.now().toIso8601String(); // the name needs to be unique every time you take a screenshot
          var path = '$directory/$fileName.png';

          File image = await File(path).writeAsBytes(result); // thanks to the answer above by @Guillaume Roux

           showDialog(
            context: context,
            builder: (context) {
              return AlertDialog(
                content: Image.file(image),
              );
            },
          );
        },
票数 0
EN

Stack Overflow用户

发布于 2021-03-04 06:43:16

以下是一个示例,其中path是图像的完整路径,并对Uint8List执行img操作

代码语言:javascript
复制
File newFile = await File(path).writeAsBytes(img);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66463576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档