本文介绍了在本机图像视图中从相机获取最近单击的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的React本机应用程序中实现了摄像头.我想在单击后在同一屏幕上的小图像视图中显示该摄像机最近捕获的图像.但是我不知道如何访问最近单击的图像.每当通过电话单击任何新图像时,都会为其指定一个默认的随机名称,该如何在图像视图的源代码中引用它?请提出一些建议.我的代码是

I am implementing camera in my react native application. I want to show the recently captured image from that camera in a small image view on the same screen after click. But I am not getting how do I access the recently clicked image. Whenever any new image is clicked through phone it has been given a default random name, how do I refer it in image view's source?Please suggest me some way to do that. My code is

 class Incident extends Component {
    constructor(props)
    {  super(props)

        this.state=  {path:"",show:false,video:Camera.constants.CaptureMode.video,camera:Camera.constants.CaptureMode.camera}
      }
    render() {
      return (
              <View style={styles.container}>
             <View style={{flex:72}}>
             <Camera
              ref={(cam) => {
               this.camera = cam;
                }}
              style={styles.preview}
               aspect={Camera.constants.Aspect.fill}
              captureMode={this.state.camera}>

          </Camera>

  </View>
  <View style={{flex:8,opacity:0.5,backgroundColor:'black'}}>

    {()=>this.showClickedImage()}

  </View>


  <View style={{flex:10,flexDirection:'row',justifyContent:'space-between',backgroundColor:'#f3396b'}}>
  <TouchableOpacity style={{flex:33,flexDirection:'column', alignItems: 'center',paddingTop:10}}>
  <Image style={styles.icon} source={require('./Images/menu.png')}/>
  <Text>Home</Text>
  </TouchableOpacity>



  <TouchableOpacity style={{flex:34,flexDirection:'column', height:70,alignItems: 'center',borderColor:'#dd1e52',borderWidth:1,paddingTop:5}}
                               onPress={()=>this.takePicture()}>
  <Image style={{width:50,height:50}} source={require('./Images/capture.png')}/>

  </TouchableOpacity>





  <TouchableOpacity style={{flex:33,flexDirection:'column', alignItems: 'center',paddingTop:10}}>
  <Image style={styles.icon} source={require('./Images/profile.png')}/>
  <Text>Profile</Text>
  </TouchableOpacity>


  </View>
  </View>
);
      }

      showClickedImage()
  {
        return <View style={{flex:1,height:40,width:40, borderWidth:1,borderColor:'black'}}>
               <Image style={{width:40,height:40}} source= {{uri: this.state.path}}/>
               </View>
               }

       takePicture()
     {

       this.camera.capture()
  .then((data) =>{console.log(data.path),this.setState({show:true}),this.setState({path:data.path})})
  .catch(err => console.error(err));
             }
            }

推荐答案

camera.capture()返回所捕获图像的路径.使用它显示在Image组件中.

camera.capture() returns path of the captured image. Use that to show in Image component.

<Image source={{uri: data.path}} style={{width: 100, height: 100}} />

这篇关于在本机图像视图中从相机获取最近单击的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 01:26