2017-12-26 55 views
1

このコードは正常に実行されましたが、アンドロイドエミュレータストレージのスクリーンショットが見つかりませんでした。どうしたの?電話機のストレージにスクリーンショットを保存するための変更が必要ですか?スクリーンショットイメージをネイティブで電話機のストレージに保存するにはどうすればよいですか?

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> 
 
    );

+0

captureScreen機能で画像を保存するため、以下のモジュールを使用してください? –

+0

"react-native-view-shot"から{captureScreen}をインポートします。 –

+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) 
     ); 
    } 
    } 
/> 
+0

ありがとう、それを試みる。 :) –

+0

また、カメラロールに保存するネイティブのデフォルト機能に対応しています。 https://facebook.github.io/react-native/docs/cameraroll.html#savetocamerarollを確認してください –

+0

私はこのモジュールに関する別のヘルプが必要です。私はそれをメールに添付したいので、保存された画像のパス/場所が必要です。そのウリを得る方法はありますか? –