UEye camera video rendering using Java and JNI
843829Aug 18 2009 — edited Aug 19 2009Hi all,
I have an UEye camera which I want to integrate with my Java application. I'm quite new to JNI, especially to the image/video related stuff.
The camera provides an SDK which allows two different ways of rendering video:
- Using DirectDraw. For this, one has to call the initialization routine providing an hWnd for the window to be displayed.
- Using device independent rendering. One sets up an event handler and listens for the 'new frame' event. Then one uses either a RenderBitmap function provided by the camera SDK to draw to a given window handle, or copy the pixel array or whatever fits with the purpose of the application.
I've tried both approaches but none of them worked properly, so I came here looking for advise. For the first approach, which sounds to me as the more suitable one, we need to obtain an hWnd. Looking through the forums and googling a bit, I found references to the JAWT library. I tried using a Canvas object which would call my JNI code for initializing the camera. My JNI code would look similar to this:
// Get AWT
awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
if(result == JNI_FALSE){
JNU_ThrowByName(...);
return;
}
// Get the drawing surface
ds = awt.GetDrawingSurface(env, mycanvas);
if(ds==NULL){
JNU_ThrowByName(...);
return;
}
// Lock the drawing surface
lock = ds->Lock(ds);
if((lock & JAWT_LOCK_ERROR) != 0){
JNU_ThrowByName(...);
return;
}
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
if(dsi==NULL){
JNU_ThrowByName(...);
return;
}
// Get the platform-specific drawing info
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
hWnd=dsi_win->hwnd;
//Unlock and free drawing surface
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
/*** Initialize camera passing obtained hWnd ***/
However, with this code the Canvas would not be updated with the images from the camera. Is there anything wrong with the code above? Is it not possible to use the window handler like this?
The other approach I took, consisted of spawning a new thread and sitting in a loop waiting for new frame events. Then, I would use the hWnd obtained above and try to draw there with the function provided by the SDK... with no success at all.
Any idea on how to do this without copying the image buffer to Java (with the associated performance loss), creating a BufferedImage object and rendering it?
Any help will be appreciated :)
Thanks in advance!