TransparencyKey 在圆角背景图像上留下像素 [英] TransparencyKey leaves pixels on rounded corner background images

查看:26
本文介绍了TransparencyKey 在圆角背景图像上留下像素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有圆角的背景图像与石灰"背景颜色相对,并将透明键设置为石灰",它主要具有仅在背景图像上显示所有表单控件的预期效果,但是圆角边缘周围 1 像素的透明键不会移除石灰背景:

I'm trying to use a background image with rounded corners against a 'lime' background colour with the transparencykey set to 'lime', it mostly has the desired effect of just showing all the form controls on the background image but the lime background is not removed from the transparency key for 1px around the rounded edges:

有谁知道我可以如何防止这种情况发生?

Does anyone know how i can prevent this happening?

推荐答案

TransparencyKey 适用于单一颜色.当您使用抗锯齿绘制圆角时,线条颜色将与背景颜色混合,因此您看到的颜色不完全是 Lime,而是 LimeGray 使圆角更平滑.因此,当您将 TransparencyKey 设置为 Lime 时,颜色将不会被移除.

TransparencyKey works with a single color. When you use anti-aliasing to draw a round corner, the line color will be mixed with the background color so the color which you see is not exactly the Lime, it's a mixture of Lime and Gray to make the round corner more smooth. So when you set TransparencyKey to Lime that color(s) will not be removed.

要获得高质量的 alpha 混合圆角,请考虑使用 分层窗口.创建一个带有透明背景的位图,其中包含圆角矩形的平滑绘制,然后使用您可以在下面的帖子中找到的技术,制作您的形状:

To have a high-quality alpha blend round corner, consider using Layered Windows. Create a bitmap with transparent background containing smooth drawing of round rectangle then using the technique which you can find in below post, make your shaped form:

使用分层窗口可以显着提高性能和具有复杂形状的窗口的视觉效果,动画其形状,或希望使用 alpha 混合效果.系统自动组合和重绘分层窗口和底层应用.结果,分层窗口被渲染平滑,没有复杂窗口区域典型的闪烁.在此外,分层窗口可以是部分半透明的,即阿尔法混合.

Using a layered window can significantly improve performance and visual effects for a window that has a complex shape, animates its shape, or wishes to use alpha blending effects. The system automatically composes and repaints layered windows and the windows of underlying applications. As a result, layered windows are rendered smoothly, without the flickering typical of complex window regions. In addition, layered windows can be partially translucent, that is, alpha-blended.

重要提示

上述技术对于创建简单的启动画面很有用,但是当您想在表单上放置一些控件时,您需要使用一种解决方法.

The technique which described above is useful for creating a simple splash screen, but when you want to place some control on your form, you need to use a workaround.

除了主窗体之外,您还可以使用 WS_EX_LAYERED 样式创建另一个窗口,并使用它来显示 alpha 混合背景图像.然后我们只需要确保这个窗口位于主窗体的后面.是的,这并不容易,但这里有一个库,它使任务变得非常简单.感谢 Anthony Mushrow 的想法和实施:

Additional to your main form, you can create another window with the WS_EX_LAYERED style and use that to show the alpha blended background image. Then we just need to make sure that this window is positioned behind the main form. Yes, this is not such easy, but here is a library which makes the task really simple. Thanks to Anthony Mushrow for the idea and implementation:

这篇关于TransparencyKey 在圆角背景图像上留下像素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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