Winforms 透明度问题(我对此感到疯狂)
我将向您展示下面的图像,但在此之前...
如果您看过雅虎小部件或卡通/主题 Windows 媒体播放器皮肤...
我正在构建一个更少的标题栏...更少的背景...应用程序...它看起来像这个
(来源:deviantart.net)
你看到的较暗的背景实际上是我的壁纸,因为这是一个屏幕截图...
为了实现这一点..身体的形状和线条,我使用透明PNG..然后我使用透明键Win Form使其透明..并且图像被加载到图片框中...
我的问题是你在整个身体轮廓上看到的白点...这是因为其中PNG的像素不完全不透明或透明,即半透明...所以透明度键无法使这些像素处的表单背景透明...并且您会看到这些白点...
好吧 有没有其他方法使表单透明,因为...
- 透明度键将始终表现得像这样,因为无论您做什么,曲线上的图像中总会有这些半透明像素...
i will show you an image below but before that...
if you have seen yahoo widgets or cartoony/themed windows media player skins..
i am building a titlebar less... background less... application... its looks like this
(source: deviantart.net)
the darker background you see is actually my wallpaper cuz this is a screen shot...
to attain this.. the shape of body and the lines, i use Trasparent PNG.. then i use the transparency key of the Win Form to make it transparent.. and the image is loaded in a picture box...
my problem is the white dots you see all over the body outline... this is because the pixels of that PNG in that are not completely opaque or transparent i.e translucent... so the transparency key fails to make the background of the form transparent at those pixels... and you see these white dots...
well
is there any other way make the form transparent because...
- transparency key will always behave like this because no matter what you do there will always be these translucent pixels in the image at curves...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是
,到目前为止,正如预期的那样。请记住:您并不是在屏幕上绘制部分透明的 PNG;而是将其绘制到屏幕上。您将其绘制到表单上,然后获取最终结果并使单色透明。不管怎样,你的 PNG 周围的颜色可以是粉红色,结果是一样的。
您可能想要查看区域或不对正在绘制的 PNG 进行抗锯齿处理。
Your problems here are
So far, so expected. Keep in mind: You're not drawing a partially-transparent PNG onto the screen; you're drawing it onto your form and you then take the end result and make a single color transparent. For all what it's worth, your PNG could have pink as the surrounding color, the result would be the same.
You may want to look at regions or don't anti-alias the PNG you're drawing.
约翰内斯提到了您当前方法的主要问题。
可以在 Windows 窗体中进行窗体 alpha 混合,但您需要使用 Windows API 调用(以及其他): 更新LayeredWindow。
Visual C# kicks 有一个有用的教程和源代码,介绍如何执行此操作来创建专业外观的启动画面。
唯一的缺点是,如果您的表单包含按钮、文本框等子控件,则不会使用 UpdateLayeredWindow 绘制它们。但是,您仍然可以通过手动将按钮等绘制为表单背景的一部分来模拟按钮等。
Johannes has mentioned the main issues with your current approach.
It is possible to do form alpha blending in Windows Forms but you will need to use the Windows API call (among others): UpdateLayeredWindow.
Visual C# kicks has a helpful tutorial and source code on how to do this to create a professional looking splash screen.
The only drawback is that if your form contains child controls such as buttons, textboxes, they will not be drawn using UpdateLayeredWindow. However you could still simulate buttons etc by manually drawing them as part of the form background.