wants to capture image in by using expo camera











up vote
1
down vote

favorite












i'm trying to capture image from expo camera but when i alert my photo nothing shown up here is complete code of my component



import React from 'react';
import { Text, View, TouchableOpacity } from 'react-native';
import { Camera, Permissions } from 'expo';
import {
Container,

Title,
Content,
Header,
Button,
Switch,
Left,
Body,
Right,

List,ListItem,Thumbnail,Footer,FooterTab
} from "native-base";
import {Icon} from 'react-native-elements';

export default class CameraEx extends React.Component {
static navigationOptions = {
header: null
}
state = {
hasCameraPermission: null,
type: Camera.Constants.Type.back,
};

async componentDidMount() {
const { status } = await Permissions.askAsync(Permissions.CAMERA);
this.setState({ hasCameraPermission: status === 'granted' });
}
takePicture = async function() {
if (this.camera) {
let photo = await this.camera.takePictureAsync();
alert(photo);

}

}

render() {
const { hasCameraPermission } = this.state;
if (hasCameraPermission === null) {
return <View />;
} else if (hasCameraPermission === false) {
return <Text>No access to camera</Text>;
} else {
return (

<Container style={{ flex: 1 }}>
<Header transparent>
<Left>
<Button transparent onPress={() =>this.props.navigation.navigate('Home') }>
<Icon name='arrow-back' />
</Button>
</Left>

</Header>
<Camera style={{ flex: 1 }} type={this.state.type}>
<View
style={{
flex: 1,
backgroundColor: 'transparent',
flexDirection: 'row',
justifyContent:'space-between',
width:"50%"
}}>
<TouchableOpacity
style={{
//flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={() => {
this.setState({
type: this.state.type === Camera.Constants.Type.back
? Camera.Constants.Type.front
: Camera.Constants.Type.back,
});
}}>
<Text
style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
{' '}Flip{' '}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={{
// flex: 0.1,
alignSelf: 'flex-end',
alignItems: 'center',
}}
onPress={()=>this.takePicture()}
>
<Text
style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
{' '}Take Picture{' '}
</Text>
</TouchableOpacity>
</View>
</Camera>
</Container>
);
}
}
}


here is a complete code my component please let me know how i can capture image and stored into state i'm beginner ............................................................................................................................................. ....










share|improve this question


























    up vote
    1
    down vote

    favorite












    i'm trying to capture image from expo camera but when i alert my photo nothing shown up here is complete code of my component



    import React from 'react';
    import { Text, View, TouchableOpacity } from 'react-native';
    import { Camera, Permissions } from 'expo';
    import {
    Container,

    Title,
    Content,
    Header,
    Button,
    Switch,
    Left,
    Body,
    Right,

    List,ListItem,Thumbnail,Footer,FooterTab
    } from "native-base";
    import {Icon} from 'react-native-elements';

    export default class CameraEx extends React.Component {
    static navigationOptions = {
    header: null
    }
    state = {
    hasCameraPermission: null,
    type: Camera.Constants.Type.back,
    };

    async componentDidMount() {
    const { status } = await Permissions.askAsync(Permissions.CAMERA);
    this.setState({ hasCameraPermission: status === 'granted' });
    }
    takePicture = async function() {
    if (this.camera) {
    let photo = await this.camera.takePictureAsync();
    alert(photo);

    }

    }

    render() {
    const { hasCameraPermission } = this.state;
    if (hasCameraPermission === null) {
    return <View />;
    } else if (hasCameraPermission === false) {
    return <Text>No access to camera</Text>;
    } else {
    return (

    <Container style={{ flex: 1 }}>
    <Header transparent>
    <Left>
    <Button transparent onPress={() =>this.props.navigation.navigate('Home') }>
    <Icon name='arrow-back' />
    </Button>
    </Left>

    </Header>
    <Camera style={{ flex: 1 }} type={this.state.type}>
    <View
    style={{
    flex: 1,
    backgroundColor: 'transparent',
    flexDirection: 'row',
    justifyContent:'space-between',
    width:"50%"
    }}>
    <TouchableOpacity
    style={{
    //flex: 0.1,
    alignSelf: 'flex-end',
    alignItems: 'center',
    }}
    onPress={() => {
    this.setState({
    type: this.state.type === Camera.Constants.Type.back
    ? Camera.Constants.Type.front
    : Camera.Constants.Type.back,
    });
    }}>
    <Text
    style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
    {' '}Flip{' '}
    </Text>
    </TouchableOpacity>
    <TouchableOpacity
    style={{
    // flex: 0.1,
    alignSelf: 'flex-end',
    alignItems: 'center',
    }}
    onPress={()=>this.takePicture()}
    >
    <Text
    style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
    {' '}Take Picture{' '}
    </Text>
    </TouchableOpacity>
    </View>
    </Camera>
    </Container>
    );
    }
    }
    }


    here is a complete code my component please let me know how i can capture image and stored into state i'm beginner ............................................................................................................................................. ....










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      i'm trying to capture image from expo camera but when i alert my photo nothing shown up here is complete code of my component



      import React from 'react';
      import { Text, View, TouchableOpacity } from 'react-native';
      import { Camera, Permissions } from 'expo';
      import {
      Container,

      Title,
      Content,
      Header,
      Button,
      Switch,
      Left,
      Body,
      Right,

      List,ListItem,Thumbnail,Footer,FooterTab
      } from "native-base";
      import {Icon} from 'react-native-elements';

      export default class CameraEx extends React.Component {
      static navigationOptions = {
      header: null
      }
      state = {
      hasCameraPermission: null,
      type: Camera.Constants.Type.back,
      };

      async componentDidMount() {
      const { status } = await Permissions.askAsync(Permissions.CAMERA);
      this.setState({ hasCameraPermission: status === 'granted' });
      }
      takePicture = async function() {
      if (this.camera) {
      let photo = await this.camera.takePictureAsync();
      alert(photo);

      }

      }

      render() {
      const { hasCameraPermission } = this.state;
      if (hasCameraPermission === null) {
      return <View />;
      } else if (hasCameraPermission === false) {
      return <Text>No access to camera</Text>;
      } else {
      return (

      <Container style={{ flex: 1 }}>
      <Header transparent>
      <Left>
      <Button transparent onPress={() =>this.props.navigation.navigate('Home') }>
      <Icon name='arrow-back' />
      </Button>
      </Left>

      </Header>
      <Camera style={{ flex: 1 }} type={this.state.type}>
      <View
      style={{
      flex: 1,
      backgroundColor: 'transparent',
      flexDirection: 'row',
      justifyContent:'space-between',
      width:"50%"
      }}>
      <TouchableOpacity
      style={{
      //flex: 0.1,
      alignSelf: 'flex-end',
      alignItems: 'center',
      }}
      onPress={() => {
      this.setState({
      type: this.state.type === Camera.Constants.Type.back
      ? Camera.Constants.Type.front
      : Camera.Constants.Type.back,
      });
      }}>
      <Text
      style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
      {' '}Flip{' '}
      </Text>
      </TouchableOpacity>
      <TouchableOpacity
      style={{
      // flex: 0.1,
      alignSelf: 'flex-end',
      alignItems: 'center',
      }}
      onPress={()=>this.takePicture()}
      >
      <Text
      style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
      {' '}Take Picture{' '}
      </Text>
      </TouchableOpacity>
      </View>
      </Camera>
      </Container>
      );
      }
      }
      }


      here is a complete code my component please let me know how i can capture image and stored into state i'm beginner ............................................................................................................................................. ....










      share|improve this question













      i'm trying to capture image from expo camera but when i alert my photo nothing shown up here is complete code of my component



      import React from 'react';
      import { Text, View, TouchableOpacity } from 'react-native';
      import { Camera, Permissions } from 'expo';
      import {
      Container,

      Title,
      Content,
      Header,
      Button,
      Switch,
      Left,
      Body,
      Right,

      List,ListItem,Thumbnail,Footer,FooterTab
      } from "native-base";
      import {Icon} from 'react-native-elements';

      export default class CameraEx extends React.Component {
      static navigationOptions = {
      header: null
      }
      state = {
      hasCameraPermission: null,
      type: Camera.Constants.Type.back,
      };

      async componentDidMount() {
      const { status } = await Permissions.askAsync(Permissions.CAMERA);
      this.setState({ hasCameraPermission: status === 'granted' });
      }
      takePicture = async function() {
      if (this.camera) {
      let photo = await this.camera.takePictureAsync();
      alert(photo);

      }

      }

      render() {
      const { hasCameraPermission } = this.state;
      if (hasCameraPermission === null) {
      return <View />;
      } else if (hasCameraPermission === false) {
      return <Text>No access to camera</Text>;
      } else {
      return (

      <Container style={{ flex: 1 }}>
      <Header transparent>
      <Left>
      <Button transparent onPress={() =>this.props.navigation.navigate('Home') }>
      <Icon name='arrow-back' />
      </Button>
      </Left>

      </Header>
      <Camera style={{ flex: 1 }} type={this.state.type}>
      <View
      style={{
      flex: 1,
      backgroundColor: 'transparent',
      flexDirection: 'row',
      justifyContent:'space-between',
      width:"50%"
      }}>
      <TouchableOpacity
      style={{
      //flex: 0.1,
      alignSelf: 'flex-end',
      alignItems: 'center',
      }}
      onPress={() => {
      this.setState({
      type: this.state.type === Camera.Constants.Type.back
      ? Camera.Constants.Type.front
      : Camera.Constants.Type.back,
      });
      }}>
      <Text
      style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
      {' '}Flip{' '}
      </Text>
      </TouchableOpacity>
      <TouchableOpacity
      style={{
      // flex: 0.1,
      alignSelf: 'flex-end',
      alignItems: 'center',
      }}
      onPress={()=>this.takePicture()}
      >
      <Text
      style={{ fontSize: 18, marginBottom: 10, color: 'white' }}>
      {' '}Take Picture{' '}
      </Text>
      </TouchableOpacity>
      </View>
      </Camera>
      </Container>
      );
      }
      }
      }


      here is a complete code my component please let me know how i can capture image and stored into state i'm beginner ............................................................................................................................................. ....







      react-native






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 10:23









      ahmad bilal

      397




      397
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          you cannot show a picture in alert box. you need to pass the source or base64 of image to react native Image component.



          const options = {
          base64: true,
          allowsEditing: true
          };
          const data = await ImagePicker.launchCameraAsync(options);

          if (data.cancelled !== true) {
          this.setState({imageBase64: data.base64});
          }


          and then you can use like this:



          <Image source={`data:image/png;base64, ${this.state.imageBase64}`} />





          share|improve this answer























          • how i can pass this to image component ?any example ?
            – ahmad bilal
            Nov 10 at 8:45










          • @ahmadbilal check updated answer
            – gamingumar
            Nov 12 at 11:55











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223894%2fwants-to-capture-image-in-by-using-expo-camera%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          you cannot show a picture in alert box. you need to pass the source or base64 of image to react native Image component.



          const options = {
          base64: true,
          allowsEditing: true
          };
          const data = await ImagePicker.launchCameraAsync(options);

          if (data.cancelled !== true) {
          this.setState({imageBase64: data.base64});
          }


          and then you can use like this:



          <Image source={`data:image/png;base64, ${this.state.imageBase64}`} />





          share|improve this answer























          • how i can pass this to image component ?any example ?
            – ahmad bilal
            Nov 10 at 8:45










          • @ahmadbilal check updated answer
            – gamingumar
            Nov 12 at 11:55















          up vote
          0
          down vote













          you cannot show a picture in alert box. you need to pass the source or base64 of image to react native Image component.



          const options = {
          base64: true,
          allowsEditing: true
          };
          const data = await ImagePicker.launchCameraAsync(options);

          if (data.cancelled !== true) {
          this.setState({imageBase64: data.base64});
          }


          and then you can use like this:



          <Image source={`data:image/png;base64, ${this.state.imageBase64}`} />





          share|improve this answer























          • how i can pass this to image component ?any example ?
            – ahmad bilal
            Nov 10 at 8:45










          • @ahmadbilal check updated answer
            – gamingumar
            Nov 12 at 11:55













          up vote
          0
          down vote










          up vote
          0
          down vote









          you cannot show a picture in alert box. you need to pass the source or base64 of image to react native Image component.



          const options = {
          base64: true,
          allowsEditing: true
          };
          const data = await ImagePicker.launchCameraAsync(options);

          if (data.cancelled !== true) {
          this.setState({imageBase64: data.base64});
          }


          and then you can use like this:



          <Image source={`data:image/png;base64, ${this.state.imageBase64}`} />





          share|improve this answer














          you cannot show a picture in alert box. you need to pass the source or base64 of image to react native Image component.



          const options = {
          base64: true,
          allowsEditing: true
          };
          const data = await ImagePicker.launchCameraAsync(options);

          if (data.cancelled !== true) {
          this.setState({imageBase64: data.base64});
          }


          and then you can use like this:



          <Image source={`data:image/png;base64, ${this.state.imageBase64}`} />






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 11:55

























          answered Nov 9 at 20:07









          gamingumar

          13415




          13415












          • how i can pass this to image component ?any example ?
            – ahmad bilal
            Nov 10 at 8:45










          • @ahmadbilal check updated answer
            – gamingumar
            Nov 12 at 11:55


















          • how i can pass this to image component ?any example ?
            – ahmad bilal
            Nov 10 at 8:45










          • @ahmadbilal check updated answer
            – gamingumar
            Nov 12 at 11:55
















          how i can pass this to image component ?any example ?
          – ahmad bilal
          Nov 10 at 8:45




          how i can pass this to image component ?any example ?
          – ahmad bilal
          Nov 10 at 8:45












          @ahmadbilal check updated answer
          – gamingumar
          Nov 12 at 11:55




          @ahmadbilal check updated answer
          – gamingumar
          Nov 12 at 11:55


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53223894%2fwants-to-capture-image-in-by-using-expo-camera%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Landwehr

          Reims

          Schenkenzell