Winforms 透明度问题(我对此感到疯狂)

发布于 2024-09-12 19:10:42 字数 709 浏览 8 评论 0原文

我将向您展示下面的图像,但在此之前...

如果您看过雅虎小部件或卡通/主题 Windows 媒体播放器皮肤...

我正在构建一个更少的标题栏...更少的背景...应用程序...它看起来像这个

alt文本
(来源: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

alt text
(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

来日方长 2024-09-19 19:10:42

您的问题是

  • PNG 是抗锯齿的
  • 它是根据普通表单背景 (SystemColors.Control) 合成的
  • 如果您使用 TransparencyKey 属性使其透明(这使得单一颜色透明,但没有其他),最终会出现不透明,而 PNG 具有部分透明度

,到目前为止,正如预期的那样。请记住:您并不是在屏幕上绘制部分透明的 PNG;而是将其绘制到屏幕上。您将其绘制到表单上,然后获取最终结果并使单色透明。不管怎样,你的 PNG 周围的颜色可以是粉红色,结果是一样的。

您可能想要查看区域或不对正在绘制的 PNG 进行抗锯齿处理。

Your problems here are

  • The PNG is anti-aliased
  • It is composited against the normal form background (SystemColors.Control)
  • If you make that transparent using the TransparencyKey property (which makes a single color transparent, but nothing else), you'll end up having opaqueness where the PNG had partial transparency

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.

二智少女 2024-09-19 19:10:42

约翰内斯提到了您当前方法的主要问题。

可以在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文