如何使控件透明地覆盖DirectShow视频?

时间:2022-12-14 15:52:53

I have a control, VideoControl, which displays video using DirectShow - it's set as the owner of an IVideoWindow. I have another control, AreaControl, which is supposed to show a dashed rectangle over the video control. AreaControl is set to be transparent using SetStyle(ControlStyles.SupportsTransparentBackColor, true). If I place AreaControl over any other control, it works as expected, showing a dashed rectangle over the controls behind it. But when I place the dashed rectangle control over the video control, the AreaControl is filled in with the VideoControl's BackColor.

我有一个控件,VideoControl,它使用DirectShow显示视频 - 它被设置为IVideoWindow的所有者。我有另一个控件,AreaControl,它应该在视频控件上显示一个虚线矩形。使用SetStyle(ControlStyles.SupportsTransparentBackColor,true)将AreaControl设置为透明。如果我将AreaControl放在任何其他控件上,它会按预期工作,在其后面的控件上显示一个虚线矩形。但是当我将虚线矩形控件放在视频控件上时,AreaControl将使用VideoControl的BackColor填充。

What do I need to do to get the video to display through the AreaControl, with the dashed rectangle overlaid on it? Is there a way to get the VideoControl to paint itself with the video, rather than just drawing its BackColor?

我需要做什么才能通过AreaControl显示视频,并在其上叠加虚线矩形?有没有办法让VideoControl用视频绘制自己,而不仅仅是绘制BackColor?

2 个解决方案

#1


1  

As far as I know, there is no way of doing, what you want to do directly. The problem is, the implementation of the transparent style of a control. A control with this style attribute basically just draws, what is behind it making it appear transparent. (In reality it isn't really transparent at all).

据我所知,没有办法,你想直接做什么。问题是,执行透明样式的控件。具有此样式属性的控件基本上只是绘制,它背后的内容使它看起来透明。 (实际上它根本不是透明的)。

The only solution that comes to my mind is to use a window (Form) and put the control in that. A Form can be made transparent by setting its Opacity property to something less than 1.0. A value of 0.0 will be totally transparent (read: Invisible). The dashed border should be totally black. With a opacity of f.e. 0.4 it will appear gray.

我想到的唯一解决方案是使用一个窗口(Form)并将控件放入其中。通过将其Opacity属性设置为小于1.0的值,可以使Form变为透明。值0.0将完全透明(读:不可见)。虚线边框应该是全黑的。不透明度为f.e. 0.4它会显示为灰色。

Alternatively, you may have some luck with TransparencyKey Property of the Form. Setting this to white may have the desired effect, but I haven't tested this one.

或者,您可以通过表格的TransparencyKey属性获得一些运气。将其设置为白色可能会产生预期的效果,但我还没有测试过这个效果。

In either case the Form should be completely borderless. You may have to add some code to reposition the form, when the video form moves.

在任何一种情况下,表格应完全无边界。当视频表单移动时,您可能必须添加一些代码来重新定位表单。

#2


0  

In the end the answer to this turned out to be to use the AreaControl's Region property, since we didn't need partial transparency.

最后,答案是使用AreaControl的Region属性,因为我们不需要部分透明度。

#1


1  

As far as I know, there is no way of doing, what you want to do directly. The problem is, the implementation of the transparent style of a control. A control with this style attribute basically just draws, what is behind it making it appear transparent. (In reality it isn't really transparent at all).

据我所知,没有办法,你想直接做什么。问题是,执行透明样式的控件。具有此样式属性的控件基本上只是绘制,它背后的内容使它看起来透明。 (实际上它根本不是透明的)。

The only solution that comes to my mind is to use a window (Form) and put the control in that. A Form can be made transparent by setting its Opacity property to something less than 1.0. A value of 0.0 will be totally transparent (read: Invisible). The dashed border should be totally black. With a opacity of f.e. 0.4 it will appear gray.

我想到的唯一解决方案是使用一个窗口(Form)并将控件放入其中。通过将其Opacity属性设置为小于1.0的值,可以使Form变为透明。值0.0将完全透明(读:不可见)。虚线边框应该是全黑的。不透明度为f.e. 0.4它会显示为灰色。

Alternatively, you may have some luck with TransparencyKey Property of the Form. Setting this to white may have the desired effect, but I haven't tested this one.

或者,您可以通过表格的TransparencyKey属性获得一些运气。将其设置为白色可能会产生预期的效果,但我还没有测试过这个效果。

In either case the Form should be completely borderless. You may have to add some code to reposition the form, when the video form moves.

在任何一种情况下,表格应完全无边界。当视频表单移动时,您可能必须添加一些代码来重新定位表单。

#2


0  

In the end the answer to this turned out to be to use the AreaControl's Region property, since we didn't need partial transparency.

最后,答案是使用AreaControl的Region属性,因为我们不需要部分透明度。