如何将屏幕截图图像保存到手机存储中?

时间:2017-12-26 04:57:20

标签: reactjs react-native save storage screenshot

此代码运行成功,但未在Android模拟器存储中找到屏幕截图。有什么问题?在手机存储中保存屏幕截图是否需要进行任何更改?

return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native SnapShot!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <Button
          onPress={
            () => {
            captureScreen({
              format: "jpg",
              quality: 0.8
            })
            .then(
              uri => console.log("Image saved to", uri),
              error => console.error("Oops, snapshot failed", error)
            );
          }
          }
          title="capture"
          color="#841584"
          accessibilityLabel="Capture"
        />
      </View>
    );

1 个答案:

答案 0 :(得分:1)

请使用以下模块将图像保存在本地存储https://github.com/francisco-sanchez-molina/react-native-store-photos-album

import CameraRollExtended from 'react-native-store-photos-album'
<Button
  onPress = {
    () => {
      captureScreen({
          format: "jpg",
          quality: 0.8
        })
        .then(
          uri => {
            CameraRollExtended.saveToCameraRoll({
              uri: uri,
              album: 'Name'
            }, 'photo')
          },
          error => console.error("Oops, snapshot failed", error)
        );
    }
  }
/>