开发者

directshow.net webcam overlay transparent panel

开发者 https://www.devze.com 2023-04-12 02:52 出处:网络
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 D

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 move开发者_运维技巧able 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:

directshow.net webcam overlay transparent panel

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号