如何使图片框透明? [英] How to make a picturebox transparent?

查看:101
本文介绍了如何使图片框透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用直播节目来捕捉视频我面临的问题,我必须在显示实时视频的图片框上放置一个图片框(称之为相机盒)。我试图使图片框背景透明,相机盒成为图片框的父母,但是当我运行代码时,图片框就消失了。此外,我尝试进行自定义控件并覆盖背景以使其透明,但是当我运行代码时,我发现我必须使用计时器刷新表单。当我用计时器刷新时,自定义控件消失并出现(闪烁)。

我不知道该怎么做。我的问题是有没有办法在相机盒上显示透明的图片框(显示实时视频的图片框)???

I''m using direct show to capture video the problem that I faced that I have to to put a picturebox over the picturebox which displays the live video (call it camerabox). I tried to make the picturebox background transparent and the camerabox the parent of the picture box but when I run the code the picturebox disappeared. Also, I tried to make a custom control and override the background to make it transparent but when I run the code I found that I have to refresh the form with a timer. When I refreshed with a timer the customcontrol disappears and appear (make like flashes).
I don''t know what to do. My question is there any way to make a transparent picturebox over the camerabox(the picturebox that displays the live video) ???

推荐答案

你真的不能做那。 Windows窗体中的控件永远不会真正透明。透明颜色只告诉控件它应该采用托管它的控件的背景属性,赋予ILLUSION透明度。



问题是即使您可以看到控件所在表单的背景,您也看不到控件和表单之间的任何控件。这是因为当一个控件被放置在窗体上时,它会控制绘制控件的所有像​​素。控件后面的任何控件都不会在这些像素中自行绘制,因此,你无法控制它通过你的控制来看看。



你不能使用控件来做到这一点。您要么自己自定义绘制覆盖层,要么废弃Windows窗体并切换到WPF,这样做更容易。



自定义绘画也很难因为你必须在视频帧之间不断重新绘制叠加层。我们甚至不会开始认为会有这方面的教程。
You really can''t do that. Controls in Windows Forms are never really transparent. The Transparent color only tells the control that it should take on the background properties of the control that is hosting it, giving the ILLUSION of transparency.

The problem with this is that even though you can see the background of the form your control is sitting on, you cannot see any controls that sit between your control and the form. This is because when a control is placed on the form it OWNS all of the pixels that the control is drawn in. Any controls that sit behind your control do not paint themselves in those pixels, therefor, there''s no control there for you to see through your control.

You cannot use a control to do this. You either have to custom paint the overlay yourself or scrap Windows Forms and switch to WPF, where this is much easier to do.

Custom painting will also be very difficult to pull off because you have to constantly repaint your overlay in between frames of the video. Don''t even begin to think there will be a tutorial for this.


这篇关于如何使图片框透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆