react-native-camera-kit
react-native-camera-kit copied to clipboard
capture() function not working
Issue Description
The function async onCaptureImagePressed() on CameraScreen does not work and capture() dont work either, whether i use promise or not, i f I dont use the promise i just get '{"_U": 0, "_V": 0, "_W": null, "_X": null}', if i use the promise the code is not executed after. I have try Camera and. CameraScreen components
Steps to Reproduce / Code Snippets / Screenshots
this is not fixed, I am using latest release @aarongrider
try {
let t1 = this.camera.capture();
console.log(t1);
} catch (e) {
console.log(e);
}
const image = await this.camera.capture();
console.log(image);
Environment
- React Native Navigation version: 0.63.4
- React Native version: 16.13.1
- Platform(s) (iOS, Android, or both?): Android for now, haven’t tested on ios yet.
- Device info (Simulator/Device? OS version? Debug/Release?): Android 8.0, sdk 26, CAT device.
[UPDATES:]
It works with classpath('com.android.tools.build:gradle:4.1.1')
but not classpath("com.android.tools.build:gradle:4.2.0")
;
The captured images don’t have a correct uri, or type, when trying to use the uri, it wont render in image.
{
"height": 1920,
"id": "/external/images/media/691",
"name": "691",
"path": "/external/images/media/691",
"uri": "content://media/external/images/media/691",
"width": 1080
}
please update for com.android.tools.build:gradle:4.2.x
. I'm using react-native v0.65.1
and have error when use com.android.tools.build:gradle:4.1.x
Try saving the camera reference to the state.
I'm getting this problem. Just tried saving camera reference to state, but don't see any difference. Did it work for anyone else?
It should work. I have already tried that earlier. Please check again. You might have missed something.
@DibyajyotiMishra It's not working no matter what I do. I've tried putting the camera ref in state, using different components (Camera vs CameraScreen). Tried changing all different props, and just using it with a few props as possible.
It hangs on camera.capture()
, only on Android. If the component is dismounted it then shows an error that says "Camera is closed" - otherwise I've waited 10 minutes for it to do anything after capture() and it just doesn't do it. No code after capture() is executed. I've even tried not using await
and just executing it synchronously.
This is on Pixel 5, API 32 (Android 12)
It turned out to be something to do with the "virtual scene" that android emulates. If I set the emulator to just "emulate" the camera, instead of using a virtual scene, it works
It turned out to be something to do with the "virtual scene" that android emulates. If I set the emulator to just "emulate" the camera, instead of using a virtual scene, it works
Did you manage to run on the physical device? it works?
my problem was solved by using this
const {uri}= await webcamRef?.current?.capture?.(); and Im using classpath('com.android.tools.build:gradle:4.1.1')
[UPDATE]
works with classpath("com.android.tools.build:gradle") as well
When you see '{"_U": 0, "_V": 0, "_W": null, "_X": null}
output, it usually means you are logging the output of a promise. You can't rely on the exact characters here, but I've seen this before.
Make sure you await
or .then(...)
the promise returned by .capture()
.
Also make sure you access .current
before you call .capture
as such:
const myRef = useRef(); myRef.current.capture()
- notice the .current.
See this example code: https://github.com/teslamotors/react-native-camera-kit/blob/master/example/src/CameraExample.tsx#L81