无法让渐变透明边框正确显示
我无法让表单背景图像以渐变透明度正确显示。也就是说,图像的边缘(或任何地方)具有褪色或非 255 Alpha 值。结果是,在 Alpha 不是 255(或 0 - 我不记得)的地方,我看到了我的背景颜色。 是屏幕截图:
这 我在此设置中有一个带有绿色背景的 24 位 bmp 文件,我试图通过 Form.TransparencyKey 属性键入该文件:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Color key = ((Bitmap)this.BackgroundImage).GetPixel(0, 0);
this.TransparencyKey = key;
}
我还尝试将 Form 的 BackColor 属性设置为相同的键值,但这没有什么区别。
我还尝试将图像保存为具有透明度的 png 并抠出整个表单背景,但这也不起作用。
我知道这是可能的,我已经看到像 Photoshop 这样的应用程序使用它已有十年了。如果这很重要的话,我使用的是WinXP Pro。
任何人都有这方面的经验,并知道我错过了什么步骤或做得不正确吗?
I am having trouble getting my Form background image to display correctly with a gradient transparency. That is, the edge of the image (or anywhere for that matter) has a fading or non-255 Alpha value. The result is that everywhere the Alpha is NOT 255 (or 0 - I can't remember) I see my background color. Here is a screen shot:
What I have in this setup is a 24bit bmp file with a green background that I'm trying to key out via the Form.TransparencyKey property:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Color key = ((Bitmap)this.BackgroundImage).GetPixel(0, 0);
this.TransparencyKey = key;
}
I have also tried setting the Form's BackColor property to the same key value but that did not make a difference.
I also tried saving my image as a png with transparency and keying out the entire form background but that didn't work either.
I know this is possible somehow, I've seen applications like Photoshop use this for a decade. I'm on WinXP Pro if that matters.
Anyone have experience with this and have an idea what step I'm missing or doing incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Form
的 WinForms 实现仅允许使用纯色作为透明度键。不可能有不同程度的透明度。大多数具有像您这样的启动屏幕的应用程序都会截取桌面屏幕截图(在其启动屏幕将占据的范围内),然后将其启动屏幕合成在此屏幕截图之上。然后,它们向用户显示生成的位图,给人一种 alpha 渐变的印象。
The WinForms implementation of
Form
only permits a solid colour to be used as the transparency key. It's not possible to have varying levels of transparency.Most apps with splash screens like yours take a screenshot of the desktop (within the bounds that their splash screen will occupy) and then composite their splash screen on top of this screenshot. They then display the resulting bitmap to the user, giving the impression of an alpha gradient.
我也曾经历过这样的失败。
我发现 WinForms 在处理这个问题上很弱。
以下是一些您可能会觉得有用的解决方案:
http://www.c-sharpcorner.com/UploadFile/scottlysle/ XparentFormsCS10282007212944PM/XparentFormsCS.aspx
链接
http://www.vcskicks.com/splash-screen.php
I've had my share of failure time with exactly that.
I found that WinForms is simple weak at handling this.
Here is some solutions that you might find useful:
http://www.c-sharpcorner.com/UploadFile/scottlysle/XparentFormsCS10282007212944PM/XparentFormsCS.aspx
Link
http://www.vcskicks.com/splash-screen.php