简体   繁体   English

C#遍历颜色?

[英]C# Looping through Colors?

In my program, I need to cycle through the Known user colors available in order so it looks smooth and natural, like the DWM color slider. 在我的程序中,我需要循环浏览可用的已知用户颜色,以使其看起来像DWM颜色滑块一样平滑自然。

The colors have to be converted to a uint aswell 颜色也必须转换为uint

private static uint ColorToBgra(Color     
{
   return (uint)
   (color.B | (color.G << 8) | (color.R << 16) | (color.A << 24));
}

Then set it. 然后设置它。 I tried setting it to white which uint is 0 then adding +1 every 0.1 seconds, but it isn't smooth and at intervals of about uint 250 it'll turn black then proceed. 我尝试将其设置为uint为0的白色,然后每0.1秒添加+1,但是它并不平滑,每间隔大约uint 250,它将变黑然后继续。 Would this work for me?I tried it but it doesn't. 这项功能对我有用吗?我尝试过,但没有。

Any ideas? 有任何想法吗?

This might push you in the right direction? 这可能会把您推向正确的方向?

// w goes from 0 to 100
private static Color spectrumColor(int w)
{
  float r = 0.0f;
  float g = 0.0f;
  float b = 0.0f;

  w = w % 100;

  if (w < 17) {
    r = -(w - 17.0f) / 17.0f;
    b = 1.0f;
  } else if (w < 33) {
    g = (w - 17.0f) / (33.0f - 17.0f);
    b = 1.0f;
  } else if (w < 50) {
    g = 1.0f;
    b = -(w - 50.0f) / (50.0f - 33.0f);
  } else if (w < 67) {
    r = (w - 50.0f) / (67.0f - 50.0f);
    g = 1.0f;
  } else if (w < 83) {
    r = 1.0f;
    g = -(w - 83.0f) / (83.0f - 67.0f);
  } else {
    r = 1.0f;
    b = (w - 83.0f) / (100.0f - 83.0f);
  }

  return Color.FromArgb((int)r * 255, (int)g * 255, (int)b * 255);
}

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

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