I’m encountering an issue when trying to take a picture using the react-native-camera library in my React Native app. The takePicture function fails with the following error:
I’m using the following code to take a picture:
const takePicture = async () => {
if (camera) {
try {
await camera.resumePreview();
await new Promise(resolve => setTimeout(resolve, 100));
const data = await camera.takePictureAsync();
console.log('Picture taken', data);
const image = {
localPath: data.uri,
imageType: vehicleImageIndex,
};
const updatedPictures = [...cameraPictures];
updatedPictures[vehicleImageIndex] = image;
setCameraPictures(updatedPictures);
setVehicleImageIndex(prevIndex => prevIndex + 1);
} catch (error) {
console.error('Error taking picture: ', error);
}
} else {
console.log('Camera not ready');
}
};
I’ve tried the following to resolve the issue but to no avail:
- Checked camera permissions in AndroidManifest.xml
- Verified the camera object is properly initialized
- Added a delay before calling takePictureAsync()
Has anyone faced a similar issue or has any idea how to fix this? Any help would be appreciated.
Environment:
- React Native version: “0.71.15”,
- react-native-camera version: “^4.2.1”