【问题标题】:Convert Uint8List image data to ImageGallerySaver saveFile String将 Uint8List 图像数据转换为 ImageGallerySaver saveFile String
【发布时间】:2021-08-01 04:32:04
【问题描述】:

如何将Screenshot Package的Uint8List图像数据用ImageGallerySaver package saveFile命令进行保存,需要字符串?

               TextButton(
                onPressed: () {
                  _imageFile = null;
                  screenshotController
                      .capture()
                      .then((Uint8List image) async {
                    //print("Capture Done");
                    setState(() {
                      _imageFile = image;
                    });
                    final result = await ImageGallerySaver.saveFile(); 
                    print("File Saved to Gallery");
                  }).catchError((onError) {
                    print(onError);
                  });

【问题讨论】:

    标签: image flutter file


    【解决方案1】:

    我找到了解决办法:

    TextButton(
                    onPressed: () {
                      _imageFile = null;
                      screenshotController
                          .capture()
                          .then((Uint8List image) async {
                        //print("Capture Done");
                        String dir =
                            (await getApplicationDocumentsDirectory()).path;
                        File file = File("$dir/" +
                            DateTime.now().millisecondsSinceEpoch.toString() +
                            ".png");
                        await file.writeAsBytes(image);
    
                        setState(() {
                          _imageFile = image;
                        });
                        final result =
                            await ImageGallerySaver.saveFile(file.path);
                        print("File Saved to Gallery");
                      }).catchError((onError) {
                        print(onError);
                      });
                    },
                    child: Icon(Icons.change_history),
                  ), // Thi
    

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 2021-08-24
      • 2021-04-05
      • 2020-05-20
      • 2022-10-05
      • 2023-03-10
      • 2020-06-15
      • 2020-03-06
      • 2021-09-19
      相关资源
      最近更新 更多