给定基色计算渐变填充的开始颜色和结束颜色

发布于 2024-08-19 19:28:07 字数 322 浏览 4 评论 0原文

我有一个 WTL C++ 应用程序,我希望用户能够为某些 UI 元素选择不同的颜色,并使用 GradientFill API 调用应用渐变填充。但是,我希望他们能够选择“基”颜色,并让我的应用程序自动计算合适的开始/结束颜色,而不是让用户选择渐变的开始和结束颜色。我希望最终获得与 Windows 用于各种主题元素的填充类似的填充。基色可以是渐变的“中间”颜色,我的应用程序以某种方式计算渐变开始的稍浅的颜色和渐变结束的稍深的颜色。或者,我可以使用基础颜色作为起始颜色并计算结束颜色,反之亦然。

我确信使用一些 RGB 宏魔法这会相对容易,但我真的不知道从哪里开始。任何想法都会受到欢迎。

I have a WTL C++ application and I want the user to be able to select different colours for some of the UI elements and apply a gradient fill using the GradientFill API call. However, instead of letting the user pick the start and end colours for the gradient, I'd like them to be able to select a 'base' colour and for my application to calculate suitable start/end colours automatically. I want to end up with a fill that is similar to the one Windows uses for various themed elements. The base colour could be the 'middle' colour of the gradient with my application somehow computing a slightly lighter colour for the gradient start and a slightly darker colour for the gradient end. Alternatively I could use the base as the start colour and compute the end or vice-versa.

I'm sure this would be relatively easy with some RGB macro magic but I really don't know where to start. Any ideas would be welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

℉服软 2024-08-26 19:28:07

RGB 色彩空间不适合这种情况。使用HSL或HSV:通过改变个体很容易自动生成好看的渐变成分。您可以在 API 中使用的从 HSL/V 转换为 RGB 三元组的方法是 简单

The RGB color space is not suitable for this. Use HSL or HSV: it is easy to auto-generate a good looking gradient by varying an individual component. Converting from HSL/V to an RGB triplet you can use in the API is simple.

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