Java does not have unsigned integer types, but the camera does not really care. You can safely cast the byte array that arrives from onPictureTaken()
callback to uint8_t*
.
Sidenote: most likely, the picture will arrive as JPEG stream.
Update: Example of implementing onPictureTaken()
in C.
Here is what you have somewhere in your activity:
mCamera = Camera.open();
mCamera.setPreviewDisplay(surfaceHolder);
mCamera.startPreview();
...
mCamera.takePicture(null, null, new android.hardware.Camera.NativePictureCallback);
Here is the file src/android/hardware/Camera/NativePictureCallback.java:
package android.hardware.Camera;
class NativePictureCallback: implements PictureCallback {
static {
System.loadLibrary("NativeCamera");
}
public void native onPictureTaken(byte[] data, Camera camera);
}
And here is the C file that is part of libNativeCamera.so:
include <jni.h>
include <tmwtypes.h>
real_T detection(const uint8_T* OriginalImage);
JNIEXPORT void JNICALL
Java_android_hardware_Camera_NativePictureCallback_onPictureTaken(
JNIEnv* env, jobject thiz, jbytearray data, jobject camera) {
jbyte* dataPtr = (*env)->GetByteArrayElements(env, data, NULL);
real_T res = detection((const uint8_T*)dataPtr);
(*env)->ReleaseByteArrayElements(env, data, dataPtr, JNI_ABORT);
}