我如何反转颜色/颜色? [英] How do I invert a colour / color?

查看:239
本文介绍了我如何反转颜色/颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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


解决方案

这取决于你所说的反相颜色

千万

您code提供了消极的颜色。

您是否在寻找变换红青色,绿色紫色,蓝色黄色(等)?如果是这样,你需要你的RGB颜色转换成 HSV 模式(你会发现<一个href=\"http://en.wikipedia.org/wiki/HSL%5Fand%5FHSV#Conversion%5Ffrom%5FRGB%5Fto%5FHSL%5For%5FHSV\">here使变换)。

然后你只需要反转色彩值(变化色相 360色相)和转换回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.

这篇关于我如何反转颜色/颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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