0

这是使用复制功能时的错误。如何保存从相机点击的图像?

Future _takePicture() async {
    final imageFile = await ImagePicker().getImage(
      source: ImageSource.camera,
      maxHeight: 600,
    );
    setState(() {
      _storedImage = File(imageFile.path);
    });
    final appDir = await syspaths.getApplicationDocumentsDirectory();
    final fileName = path.basename(imageFile.path);
    final savedImage = await imageFile.copy('${appDir.path}/$fileName');
  }
4

1 回答 1

3

你应该复制_storedImage而不是imageFile

imageFile类型是PickedFile和没有copy方法

Future _takePicture() async {
        final imageFile = await ImagePicker().getImage(
          source: ImageSource.camera,
          maxHeight: 600,
        );
        setState(() {
          _storedImage = File(imageFile.path);
        });
        final appDir = await syspaths.getApplicationDocumentsDirectory();
        final fileName = path.basename(imageFile.path);
        final savedImage = await _storedImage.copy('${appDir.path}/$fileName');
      }
于 2020-06-16T06:32:49.313 回答