问题描述
我知道这不会直接反转颜色,它只会反对它。我想知道是否有人知道一个简单的方法(几行代码)来反转任何给定颜色的颜色?
目前我有这个(这是'因为如果我通过它的灰色/灰色的颜色,它会返回非常相似的东西,例如127,127,127):
$ c> 360-Hue )并转换回RGB模式。I know that this won't directly invert a colour, it will just 'oppose' it. I was wondering if anyone knew a simple way (a few lines of code) to invert a colour from any given colour?
At the moment I have this (which isn't exactly the definition of an invert, because if I pass it a grey / gray colour it will return something extremely similar e.g. 127, 127, 127):
const int RGBMAX = 255; Color InvertMeAColour(Color ColourToInvert) { return Color.FromArgb(RGBMAX - ColourToInvert.R, RGBMAX - ColourToInvert.G, RGBMAX - ColourToInvert.B); }解决方案It depends on what do you mean by "inverting" a color
Your code provides a "negative" color.
Are you looking for transform red in cyan, green in purple, blue in yellow (and so on) ? If so, you need to convert your RGB color in HSV mode (you will find here to make the transformation).
Then you just need to invert the Hue value (change Hue by 360-Hue) and convert back to RGB mode.
这篇关于如何反转颜色/颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!