我想通过wechat_camera_picker flutter删除捕获的图像

发布于 2025-01-27 03:34:28 字数 819 浏览 5 评论 0原文

对于Image_picker MainAttivity破坏,我想使用其他插件来选择图像。我找到了wechat_camera_picker作为替代方案。但是捕获图像时存在问题。选择图像后,保存在本地存储上的捕获图像。这是我的代码。

Future<File> getImageByCamera(BuildContext context) async {
    try{
      final AssetEntity result = await CameraPicker.pickFromCamera(
        context,
        pickerConfig: CameraPickerConfig(
          shouldDeletePreviewFile: true,
          enableRecording: false,
          textDelegate: EnglishCameraPickerTextDelegate(),
        ),
      );
      if(result != null){
        File pickedFile = await result.file;
        pickedFile = await compressFile(pickedFile);
        return pickedFile;
      }else{
        return null;
      }
    }catch(error){
      print(error);
      return null;
    }
  }

有人对这个问题有任何解决方案吗?

For image_picker MainActivity destruction I wanted to use other plugin to pick image. And I found wechat_camera_picker as an alternative. But there was a problem while capturing the image. The captured image saved on Local Storage after selecting the image. Here is my code.

Future<File> getImageByCamera(BuildContext context) async {
    try{
      final AssetEntity result = await CameraPicker.pickFromCamera(
        context,
        pickerConfig: CameraPickerConfig(
          shouldDeletePreviewFile: true,
          enableRecording: false,
          textDelegate: EnglishCameraPickerTextDelegate(),
        ),
      );
      if(result != null){
        File pickedFile = await result.file;
        pickedFile = await compressFile(pickedFile);
        return pickedFile;
      }else{
        return null;
      }
    }catch(error){
      print(error);
      return null;
    }
  }

Does anyone have any solution of this problem?

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

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

发布评论

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

评论(1

流年里的时光 2025-02-03 03:34:28

您可以使用以下功能删除本地存储的文件。

  Future<bool> deleteFile(File pickedFile) async {
    try {
      await pickedFile.delete();
      return true; 
    } catch (e) {
      return false;
    }
  }   

您可以检查 delete function documation 用于参考的人。

you can use the below function to delete the locally stored file.

  Future<bool> deleteFile(File pickedFile) async {
    try {
      await pickedFile.delete();
      return true; 
    } catch (e) {
      return false;
    }
  }   

You can check the Delete Function Documation for referenece.

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