简体   繁体   English

directshow.net网络摄像头覆盖透明面板

[英]directshow.net webcam overlay transparent panel

I am trying to use a webcam to take photos for badges. 我正在尝试使用网络摄像头拍摄徽章的照片。 To do this I have used the directshow.net library and examples, this has got me a webcam preview screen in .NET rendered in a picturebox as per DxSnap sample. 为此,我使用了directshow.net库和示例,根据DxSnap示例,这使我获得了.NET中的网络摄像头预览屏幕,该屏幕显示在图片框中。 I now wish to overlay it with a rectangle which is moveable and resizable (locked aspect ratio) so the end user drags this over the person to take an image from the webcam at the appropriate point. 现在,我希望用一个可移动且可调整大小的矩形(锁定的宽高比)覆盖它,以便最终用户将其拖动到该人上方,以在适当的位置从网络摄像头拍摄图像。 So it would look something like this: 所以看起来像这样:

范例图片

To do this I thought no problem, the webcam source is put into a picture box I will just overlay it with a transparent panel or picture frame and use normal .NET code to make a rectangle on there. 为此,我认为没有问题,将网络摄像头源放入图片框,我将其覆盖在透明面板或图片框上,并使用普通的.NET代码在该框上制作一个矩形。 If I overlay a normal panel it appears above the directshow webcam output as expected. 如果我覆盖普通面板,则它会按预期显示在DirectShow网络摄像头输出上方。 However if I use this trick to implement a transparent panel or picturebox: 但是,如果我使用此技巧来实现透明面板或图片框:

protected override CreateParams CreateParams
{
    get
    {
        CreateParams createParams = base.CreateParams;
        createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT
        return createParams;
    }
}

protected override void OnPaintBackground(PaintEventArgs e)
{
   // Do not paint background.
}

It unfortunately appears underneath the directshow output. 不幸的是,它显示在DirectShow输出的下面。 Is there an easy way to work around this or an alternative method. 有没有一种简单的方法来解决此问题或替代方法。 I would prefer not to delve too deeply into directshow.net if avoidable, I thought this would be an easy way to avoid it. 如果可以避免,我宁愿不要对DirectShow.net进行深入研究,我认为这是避免该问题的简便方法。

I have ended up using the AForge.NET project instead of DirectShow.NET. 我最终使用了AForge.NET项目而不是DirectShow.NET。 It has some really great samples and drawing over its video output is as simple as handling its video players OnPaint event since it calls it for each frame. 它具有一些非常好的样本,并且绘制其视频输出就像处理其视频播放器的OnPaint事件一样简单,因为它针对每一帧进行调用。 It seems to take a bit more CPU but nothing too taxing. 似乎要占用更多的CPU,但不会增加任何负担。

The problem with overlaying is that video is displayed in a way different from regular GUI graphics, via specific method creating non-RGB surfaces (typically) on the video adapter. 覆盖的问题是,通过特定方法在视频适配器上创建非RGB表面(通常),视频以不同于常规GUI图形的方式显示。 As a result of this, you cannot overlap video with windows, or use GDI directly. 因此,您不能将视频与窗口重叠,也不能直接使用GDI。

You still can modify video on the way, or overlay video using special mixer. 您仍然可以在途中修改视频,或使用特殊的混音器叠加视频。

See this question: Showing a semi-transparent Image object over an IVideoWindow in C# using DirectShow.NET as it discusses a similar request. 看到这个问题: 使用DirectShow.NET在C#中的IVideoWindow上显示半透明的Image对象,因为它讨论了类似的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM