如何确定给定颜色的更深或更浅的颜色变体? [英] How do I determine darker or lighter color variant of a given color?

查看:38
本文介绍了如何确定给定颜色的更深或更浅的颜色变体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定系统或用户的任何色调的源颜色,我想要一个简单的算法,我可以使用它来计算出所选颜色的较浅或较深的变体.类似于在 Windows Live Messenger 上使用的用于设计用户界面样式的效果.

Given a source color of any hue by the system or user, I'd like a simple algorithm I can use to work out a lighter or darker variants of the selected color. Similar to effects used on Windows Live Messenger for styling the user interface.

语言是 C# 和 .net 3.5.

Language is C# with .net 3.5.

回应评论:颜色格式为 (Alpha)RGB.值作为字节或浮点数.

Responding to comment: Color format is (Alpha)RGB. With values as bytes or floats.

标记答案:就我使用的上下文(一些简单的 UI 效果)而言,我标记为已接受的答案实际上是该上下文中最简单的.但是,我也放弃了对更复杂和准确的答案的投票.任何进行更高级颜色操作并在将来找到此线程的人都应该检查一下.谢谢.:)

Marking answer: For the context of my use (a few simple UI effects), the answer I'm marking as accepted is actually the most simple for this context. However, I've given up votes to the more complex and accurate answers too. Anyone doing more advanced color operations and finding this thread in future should definitely check those out. Thanks SO. :)

推荐答案

只需将 RGB 值乘以要修改级别的量即可.如果其中一种颜色已经达到最大值,那么你就不能让它更亮(无论如何都要使用 HSV 数学.)

Simply multiply the RGB values by the amount you want to modify the level by. If one of the colors is already at the max value, then you can't make it any brighter (using HSV math anyway.)

这给出了与切换到 HSV 然后修改 V 完全相同的结果,但数学运算要少得多.只要您不想开始失去饱和度,这与切换到 HSL 然后修改 L 的结果相同.

This gives the exact same result with a lot less math as switching to HSV and then modifying V. This gives the same result as switching to HSL and then modifying L, as long as you don't want to start losing saturation.

这篇关于如何确定给定颜色的更深或更浅的颜色变体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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