使用cameraroll.savetocamerarololl将图像保存到专辑中



我正在使用rncamera,它的工作很棒(以下是我的功能(。我可以拍摄图像并将其保存到照片库。尽管有人对如何将如何保存到iOS上的特定专辑中有洞察力?我已经看到了针对Android的解决方案,该方法也没有选择。不确定如何解决这个问题。tia。我认为我可能需要编辑URI?似乎不是正确的,而只是在寻找想法。可能我需要在node_modules/react_native/libraries/cameraroll中修改库文件'cameraroll.js'?

- 阅读React-Native文档,https://facebook.github.io/reeact-native/docs/camerarololl.html

- 搜索的stackoverflow(使用Android解决方案找到线程(/google

async takePicture() {
if (this.camera) {
  const options = { quality: 0.5, based64: true }
  const data = await 
this.camera.takePictureAsync(options).then(data => 
    console.log(data.uri))
    CameraRoll.saveToCameraRoll(data.uri, 'photo'));
}

};

您需要npm安装react-native-fs ...,这是您的saveFile方法:

const saveFile = (base64) => {
  const albumPath = `${RNFS.PicturesDirectoryPath}/${APP_NAME}`;
  const fileName = `${new Date().getTime()}.png`;
  const filePathInCache = `${RNFS.CachesDirectoryPath}/${fileName}`;
  const filePathInAlbum = `${albumPath}/${fileName}`;
  return RNFS.mkdir(albumPath)
    .then(() => {
      RNFS.writeFile(filePathInCache, base64, 'base64').then(() => RNFS.copyFile(filePathInCache, filePathInAlbum)
      // Next step to show album without the need to re-boot your device:
        .then(() => RNFS.scanFile(filePathInAlbum))
        .then(() => {
          console.log('File Saved Successfully!');
        }));
    })
    .catch((error) => {
      console.log('Could not create dir', error);
    });
};

最新更新