我正在使用avicap32 api将相机预览流式传输到picturebox并成功。我的问题是,如何在其他表格/图片框中复制这些实时预览,或者可以同时将单个摄像机连接到多个容器/图片框。目前我的技术是有一个主要形式(提供者)附加到相机并使用计时器定期捕获图片框的内容并将图像放入静态图像变量。在另一种形式(订户)我也使用计时器定期获取静态图像变量的值并加载到该表单的图片框。它看起来很成功(尝试了2到3个用户表单的实例)但是当我使用mdi表单(尝试过2个实例)作为订阅者时,它只获取单个图像并停止显示图像。当我试图关闭1 mdi用户时。剩余的mdi表单恢复显示图像。什么似乎有问题.. tnx
//attachment
public bool Attach(System.Windows.Forms.Control control)
{
bool ret = false;
deviceHandle = Avicap32.capCreateCaptureWindow("", _WM_Constants.WS_VISIBLE | _WM_Constants.WS_CHILD, 0, 0, 320, 240, control.Handle, 1);
if (User32.SendMessage(deviceHandle, _WM_Constants.WM_CAP_DRIVER_CONNECT, (IntPtr)deviceNumber, (IntPtr)0).ToInt32() > 0)
{
User32.SendMessage(deviceHandle, _WM_Constants.WM_CAP_SET_SCALE, (IntPtr)(-1), (IntPtr)0);
User32.SendMessage(deviceHandle, _WM_Constants.WM_CAP_SET_PREVIEWRATE, (IntPtr)0x42, (IntPtr)0);
User32.SendMessage(deviceHandle, _WM_Constants.WM_CAP_SET_PREVIEW, (IntPtr)(-1), (IntPtr)0);
User32.SetWindowPos(deviceHandle, new IntPtr(0), 0, 0, control.Width, control.Height, 6);
ret = true;
}
return ret;
}
//capture
public Image Capture()
{
if (deviceHandle.ToInt32() != 0)
{
User32.SendMessage(deviceHandle, _WM_Constants.WM_CAP_EDIT_COPY, (IntPtr)0, (IntPtr)0);
IDataObject ido = Clipboard.GetDataObject();
if (ido.GetDataPresent(DataFormats.Bitmap))
{
return ((Bitmap)ido.GetData(DataFormats.Bitmap));
}
}
return null;
}
// image holder
public static class app_config
{
public static Image camerashot;
}
//image capturing from provider form
private void tmrCamera_Tick(object sender, EventArgs e)
{
app_config.camerashot =((CaptureDevice)cboDevices.SelectedItem).Capture();
}
//image retrieval from subscriber form
private void tmrCamera_Tick(object sender, EventArgs e)
{
picCamera.BackgroundImage = app_config.camerashot;
}
答案 0 :(得分:0)
发现问题。附带摄像头的主窗体或图片框应位于顶部窗口。我总是在mdi表格(订阅者)中以最大化窗口状态覆盖主要表单(提供者)