[英]react native vision camera freezing on taking a picture
I just need to take and store a picture.我只需要拍摄并存储一张照片。 I am using react-native-vision-camera but when I take a picture, using
.takePhoto()
method.我正在使用 react-native-vision-camera 但是当我拍照时,使用
.takePhoto()
方法。 It freezes.它冻结了。
I am also using "qualityPrioritization: "speed".我也在使用“qualityPrioritization:”速度“。
I am testing it on an android emulator.我正在 android 仿真器上对其进行测试。
const CameraPage = () => {
const devices = useCameraDevices()
const device = devices.back
const isFocused = useIsFocused()
const camera = useRef(null)
const onPressButton = async () => {
console.log(camera.current)
console.log(123)
const photo = await camera.current.takePhoto({
flash: 'off',
qualityPrioritization: "speed"
})
console.log(photo)
}
if (device == null) return <View><Text>Loading</Text></View>
return (
<View style={{flex: 1}}>
<Camera
ref={camera}
style={StyleSheet.absoluteFill}
device={device}
isActive={isFocused}
photo={true}
/>
<View style={styles.buttonContainer}>
<TouchableOpacity
style={styles.camButton}
onPress={onPressButton}
>
<Text>Click me</Text>
</TouchableOpacity>
</View>
</View>
)
I met the same problem, and here is the way I solve it.我遇到了同样的问题,这是我解决它的方法。
If you just need a demo on an android emulator, you can use takeSnapshot(...)
instead.如果您只需要在 android 仿真器上进行演示,则可以改用
takeSnapshot(...)
。
Let's go back to the guide of takePhoto()
of react-native-vision-camera .让我们 go 回到react-native-vision-camera的
takePhoto()
指南。
Right below it is takeSnapshot()
, and there has a note that writes:它的正下方是
takeSnapshot()
,并且有一个注释写道:
if you care about speed, you can use the Camera's
takeSnapshot(...)
function (Android only) which simply takes a snapshot of the Camera View instead of actually taking a photo through the Camera lens .如果您关心速度,您可以使用相机的
takeSnapshot(...)
function(仅限 Android),它只是拍摄相机视图的快照,而不是通过相机镜头实际拍摄照片。
I guess the problem that react-native-vision-camera will freeze maybe because an android emulator doesn't have a real Camera lens.我猜 react-native-vision-camera 会冻结的问题可能是因为 android 模拟器没有真正的相机镜头。
So I tried takeSnapshot(...)
instead and it worked perfectly.所以我尝试
takeSnapshot(...)
,它工作得很好。
That's all, hope this can help.就这些了,希望能帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.