Flutter 在Gallery文件夹中保存图像

Flutter 在Gallery文件夹中保存图像,flutter,Flutter,我目前正在制作一个提醒框,可以选择拍照或从图库中选择图片 目前的情况是: 我可以用图像采集器从图库中获取图片,效果非常好 现在我来谈谈我的问题: 保存捕获的图像也可以,但它保存在存储器中,因此不会显示在库中。请帮帮我 图像警报框: 图像空文件夹 制作图片: 以下是存储图像的路径: 文件:'/storage/emulated/0/Android/data/com.example.supportnfrage/files/Pictures/1cd284f4-3632-4ed8-8c6a-14d7be

我目前正在制作一个提醒框,可以选择拍照或从图库中选择图片

目前的情况是:

我可以用图像采集器从图库中获取图片,效果非常好

现在我来谈谈我的问题:

保存捕获的图像也可以,但它保存在存储器中,因此不会显示在库中。请帮帮我

图像警报框:

图像空文件夹

制作图片:

以下是存储图像的路径:

文件:'/storage/emulated/0/Android/data/com.example.supportnfrage/files/Pictures/1cd284f4-3632-4ed8-8c6a-14d7be83a8335698897692938961258.jpg'

保存图像的方法

Future getAndSaveImage() async {
    final File image = await ImagePicker.pickImage(source: ImageSource.camera);
    debugPrint(image.toString());
    if (image == null) return;

    final directory = await getExternalStorageDirectory();
    final String path = directory.path;
    this._fileName = path;
    final File localImage = await image.copy(path);
  }

I using the following dependencies / plugins:

file_picker: ^1.3.8
camera: ^0.5.2+2
image_picker: ^0.6.0+17
image_gallery_saver: ^1.1.0
path_provider: ^1.1.2

Thanks.

这是为颤振相机插件提供的。它将获取时间戳,然后将您的照片与该timeStampValue.jpg的名称一起保存在手机存储器中

Future<String> takePicture() async {
    if (!controller.value.isInitialized) {
      return null;
    }
    String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();
    final Directory extDir = await getApplicationDocumentsDirectory();
    final String dirPath = '${extDir.path}/Pictures/flutter_test';
    await Directory(dirPath).create(recursive: true);
    final String filePath = '$dirPath/${timestamp()}.jpg';

    if (controller.value.isTakingPicture) {
      return null;
    }

    try {
      await controller.takePicture(filePath);
    } on CameraException catch (e) {
      return null;
    }
    return filePath;
  }
Future takePicture()异步{
如果(!controller.value.isInitialized){
返回null;
}
字符串时间戳()=>DateTime.now().millissecondssinceepoch.toString();
最终目录extDir=wait getApplicationDocumentsDirectory();
最终字符串dirPath='${extDir.path}/Pictures/flatter_test';
等待目录(dirPath).create(递归:true);
最终字符串filePath='$dirPath/${timestamp()}.jpg';
if(controller.value.picture){
返回null;
}
试一试{
等待控制器。拍摄照片(文件路径);
}关于CameraException捕获(e){
返回null;
}
返回文件路径;
}

你已经粘贴了getImage()而不是saveImage()的方法,我编辑了内容->我还上传了一张图片->这些都在你的图库中,对吗?不,它们存储在外部存储器中嗨,我插入了你的代码片段,但相机现在无法启动。我还添加了以下行并添加到initstate()中:Future setupCameras()异步{try{cameras=wait availableCameras();_cameracontroller=new cameracontroller(cameras[0],ResolutionPreset.medium);wait{u cameracontroller.initialize();}on cameraception catch(){}如果(!_isReady)返回,则返回;setState({{u isReady=true;})摄像机现在不能启动,是什么意思?你是否遵循了该链接中提供的全部代码?嘿,是的,我遵循了该链接并将代码集成到我的项目中。这似乎保存到了应用程序的doc文件夹中,这与我OnePlus6上的gallery文件夹不同。因此,最终用户仍然无法接触到这些照片。