2

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:

Example Image

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.

PeteT
  • 18,754
  • 26
  • 95
  • 132

2 Answers2

1

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.

PeteT
  • 18,754
  • 26
  • 95
  • 132
  • If you're happy with your answer, you should mark it as the answer. – Simon Mourier Oct 18 '11 at 17:52
  • Was leaving it a bit to see if there were any other suggestions since there is an open bounty and someone else may wish to contribute alternatives for anyone looking at this later. – PeteT Oct 18 '11 at 20:37
  • This has totally saved me! Way to go. I didn't know about this library before. – ashays Nov 02 '11 at 17:34
0

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.

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158