我如何反转颜色/颜色? (C#.NET)颜色、NET

2023-09-02 21:23:56 作者:ニコチン (尼古丁)

我知道这不会直接反转颜色,它只是'反对'吧。我想知道是否有人知道一个简单的方法(的code几行)从任何给定的颜色反转颜色?

目前,我有这样的(这是不完全的反转的定义,因为如果我传递一个灰色/灰色它会返回一些非常相似,例如127,127,127):

  const int的RGBMAX = 255;

颜色InvertMeAColour(彩色ColourToInvert)
{
    返回Color.FromArgb(RGBMAX  -  ColourToInvert.R,
      RGBMAX  -  ColourToInvert.G,RGBMAX  -  ColourToInvert.B);
}
 

解决方案

这要看你是什么反相颜色

意思

您code提供了一个负的色彩。

您是否正在寻找变换红青色,绿色的紫色,蓝色黄色(等)?如果是这样,你需要转换你的RGB颜色 HSV 模式(你会发现here使变换)。

然后你只需要反转的色调值(变化色相 360色相),并转换回RGB模式。

如何iphone苹果手机设置反转颜色 色彩滤镜

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.

 
精彩推荐