Trigger event when Picturebox Image changed from its Handle
I am accessing the Webcam through "avicap32" dll file in C# and i followed the code from here. Webcam starts and its LED become active Interesting point is that image is nor set with Image property neither with BackgroundImage property it is set via picturebox Handle. Picturebox is not visible & Webcam light stays active but there is not event of picturebox that triggers when its image got changed via its Handle
what i already tried is
Picturebox Paint Event (Also not firing)
i can implement a timer/thread/background-worker to get images from picturebox at regular interval but due to performance issue i would like to apply event oriented approach. The code for connecting to Webcam is following
public void OpenConnection()
{
string DeviceIndex = Convert.ToString(DeviceID);
IntPtr oHandle = Container.Handle;
hHwnd = capCreateCaptureWindowA(ref DeviceIndex, WS_VISIBLE | WS_CHILD, 0, 0, 640, 480, oHandle.ToInt32(), 0);
// Connect to device
if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, DeviceID, 0) != 0)
{
// Set the preview scale
SendMessage(hHwnd, WM_CAP_SET_SCALE, -1, 0);
// Set the preview rate in terms of milliseconds
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
// Start previewing the image from the camera
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, -1, 0);
// Resize window to fit in picturebox
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, Container.Height, Container.Width, SWP_NOMOVE | SWP_NOZORDER);
}
else
{
// Error connecting to device close window
DestroyWindow(hHwnd);
}
}
any other solution will be welcomed only if it is native or with out any other external library as i have already explored & used other approaches like Aforge and OpenCV but these are not the requirements
链接地址: http://www.djcxy.com/p/81048.html