Flutter相机插件是否有一种方法可以预先指定拍摄的图片文件名?

3

你好,我使用的是Flutter相机插件,它的功能正常。但我的主要问题是在拍照时无法告诉插件图片文件名,在Kotlin中可以使用以下方式:

photoUri = FileProvider.getUriForFile(requireActivity(), "io.awesomedomain", photoFile) // build uri on the app storage space and specific file name -> photoFile.
captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri) // define the pic name before picture is actually taken by the camera.
startActivityForResult(captureImageIntent, REQUEST_PHOTO) // start the camera

我目前只是在flutter相机插件返回图片XFile后重命名它的文件名,但这种方法不太优化,所以我想知道是否有遗漏的地方。是否可以事先指定flutter相机插件中的文件名?

我目前使用的是最新版本:camera: ^0.7.0+2

1个回答

3

好的,看起来我对相机插件有些误解,我注意到返回的XFile将图片放在缓存目录中,并且实际上提供了一种将图片保存到更明确存储位置的方法xfile.saveTo,所以我这样做:

var appDir = appDocDirectory.parent.path; // get app directory    
file.saveTo('$appDir${Platform.pathSeparator}files${Platform.pathSeparator}${weightPicture.pictureFileName}');

因此,图片会被正确地保存在$myAppDir/files/picName.jpg下,其中files是我配置的目录,具有写入权限,而picName由应用程序根据我的要求定义。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接