【问题标题】:How can I make my react-native-camera capture fast?如何让我的 react-native-camera 快速捕捉?
【发布时间】:2019-01-21 07:12:12
【问题描述】:
  takePicture = async function() {
    if (this.camera) {
       const options = { quality: 0.5, base64: true,  }; 
       const data = await this.camera.takePictureAsync(options);         
        this.setState({path: data.uri})
    }   
  }

只要我调用我的takePicture 函数来捕获图像,相机仍然会继续移动并且不会暂停。我希望相机暂停,然后显示图像。

这里有处理Promise 的问题吗?如果是,我不知道在哪里以及如何做。

我也尝试过使用pauseAfterCapture:true,但捕获图像仍需要 1 或 2 秒。

我知道这是一个老问题,但还没有解决方案可以帮助我。请帮忙。

【问题讨论】:

    标签: reactjs react-native react-native-camera


    【解决方案1】:

    我还发现可用的相机组件非常慢,这就是我创建react-native-fast-camera 的原因,我只是将它开源以供公众使用。它是非常可定制的,完全可以通过 react 原生组件来控制。

    注意:目前 Android 版本仍在开发中。

    这是一个例子:

    import FastCamera, { Methods } from 'react-native-fast-camera';
    
    
    <FastCamera style={{ height: cameraHeight, width: cameraWidth }}
        onSaveSuccess={imageUrl => {
          console.log("onSaveSuccess: ", imageUrl);
        }}
        onGalleryImage={imageUrl => {
          console.log("onGalleryImage: ", imageUrl);
        }}
        onFlashToggle={isflashOn => {
          console.log('flash info: ', isflashOn);
        }}
      >
        {/* here render your buttons to control the camera component */}
        <Button 
          title="capture picture"
          onPress={()=> Methods.takePicture();}
        />
      </FastCamera>
    

    这是一个截图:

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多