【发布时间】:2021-09-06 21:52:11
【问题描述】:
我有一个捕捉银行卡的功能,如何在相机遮罩内裁剪银行卡的图像。我使用 react-native-camera 拍照,使用 BarcodeMask 制作蒙版。代码如下:
<View style={{flex: 1}}>
<RNCamera
ref={ref => {
this.camera = ref;
}}
style={
this.state.step == 3 ? styles.camview : styles.preview
}
type={this.state.typeCamera}
autoFocus={RNCamera.Constants.AutoFocus.on}
captureAudio={false}
onFacesDetected={res =>
this.checkStatusFace(res.faces[0])
}
onFaceDetectionError={res => {
console.log('loi vao', res);
}}
faceDetectionClassifications={
RNCamera.Constants.FaceDetection.Classifications.all
}
/>
<BarcodeMask
width={350}
height={250}
showAnimatedLine={false}
/>
<TouchableOpacity
onPress={this.takePicture.bind(this)}
style={styles.capture}>
<FontAwesome5 name="camera" size={40} />
</View>
takePicture = async () => {
console.log('Da chup anh');
if (this.camera) {
const options = {quality: 0.4, base64: true};
const data = await this.camera.takePictureAsync(options);
this.setState({
uriImage: data.base64,
viewImage: true,
});
console.log(data);
}
};
【问题讨论】:
标签: reactjs react-native react-hooks react-native-camera react-native-image-picker