简体   繁体   中英

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. 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. If I overlay a normal panel it appears above the directshow webcam output as expected. 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. 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.

I have ended up using the AForge.NET project instead of 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. It seems to take a bit more CPU but nothing too taxing.

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. As a result of this, you cannot overlap video with windows, or use GDI directly.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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