简体   繁体   English

获取特定颜色的 RGB 颜色范围

[英]Getting RGB color range for specific colors

I need to get the RGB color ranges of some basic colors.我需要获取一些基本颜色的 RGB 颜色范围。 ex Red color is between RGB(a,b,c) to RGB(x,y,z) like wise or using its Hue value.Any suggestions are welcome. ex 红色介于 RGB(a,b,c) 到 RGB(x,y,z) 之间,明智地或使用其色调值。欢迎提供任何建议。

I don't think anyone can answer this in a convincing way as it is all based on the opinion of the person answering.我认为没有人能以令人信服的方式回答这个问题,因为这一切都基于回答者的意见。 What do you really consider Red ?你真正认为红色是什么?

Consider G = 0 and B = 0 , now start increasing R from 0 step by step.考虑G = 0B = 0 ,现在开始逐步从0增加 R。 People would argue, is (100, 0, 0) a valid red for you ?人们会争辩说, (100, 0, 0)对你来说是一个有效的红色吗? Or (150, 0, 0) is the start range for you ?或者(150, 0, 0)是你的起始范围? You really need to test this yourself.你真的需要自己测试一下。

The below is not scientific at all, it is only based on my opinion:以下完全不科学,仅基于我的观点:

I would consider Red starting from (160, 0, 0) going up to (255, 0 0) .我会考虑 Red 从(160, 0, 0)开始到(255, 0 0)

Also, When R = 255 .此外,当R = 255 时 I would consider any value (R= 255, G = g, B = b) where g > b as Red.我会考虑任何值(R = 255,G = g,B = b) ,其中g > b为红色。 Until you reach (g = 200 and b = 200) when it starts actually being white.直到达到(g = 200 和 b = 200)时,它才真正开始变成白色。

But when b > g , you'll get a color that may be considered a variation of red until certain range.但是当b > g 时,你会得到一种颜色,在特定范围内可能被认为是红色的变体。

Conclusion: There is no correct answer for this.结论:对此没有正确的答案。 You really need to test it out and check what best match your requirement.您确实需要对其进行测试并检查什么最符合您的要求。

Here is a javascript approach to come up with an array of rgb values between two rgb values.这是一种在两个 rgb 值之间提出 rgb 值数组的 javascript 方法。

const lightestColor = 'rgb(204, 224, 245)';
const darkestColor = 'rgb(0, 102, 206)';
const length = 5

const colorArray = this._interpolateColors(
      lightestColor,
      darkestColor,
      length
    );

// interpolate between two colors completely, returning an array of rgb values
  private _interpolateColors(color1, color2, steps): string[] {
    const stepFactor = 1 / (steps - 1);
    const rgbArray = [];

    color1 = color1.match(/\d+/g).map(Number);
    color2 = color2.match(/\d+/g).map(Number);

    for (let i = 0; i < steps; i++) {
      const color = this._interpolateColor(color1, color2, stepFactor * i);
      const string = color.join(', ');
      rgbArray.push('rgb(' + string + ')');
    }

    return rgbArray;
  }

  // Returns a single rgb color interpolation between given rgb color
  // based on the factor given; via https://codepen.io/njmcode/pen/axoyD?editors=0010
  private _interpolateColor(color1, color2, factor): number[] {
    if (arguments.length < 3) {
      factor = 0.5;
    }
    const result = color1.slice();
    for (let i = 0; i < 3; i++) {
      result[i] = Math.round(result[i] + factor * (color2[i] - color1[i]));
    }
    return result;
  }

console.log('colorArray. -->', colorArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM