C# 创建一个漂亮的调色板
我正在尝试创建一个组合框,在这里我可以选择一种颜色(之后用于绘制图表的线条) 我已经玩了一些类似的游戏:C# 创建一个漂亮的调色板,c#,wpf,colors,C#,Wpf,Colors,我正在尝试创建一个组合框,在这里我可以选择一种颜色(之后用于绘制图表的线条) 我已经玩了一些类似的游戏: int interval = 120; for (int red = 0; red < 255; red += interval) { for (int green = 0; green < 255; green += interval) { for
int interval = 120;
for (int red = 0; red < 255; red += interval)
{
for (int green = 0; green < 255; green += interval)
{
for (int blue = 0; blue < 255; blue += interval)
{
if (red > 150 | blue > 150 | green > 150 ) //to make sure color is not too dark
{
ComboBoxItem item = new ComboBoxItem();
item.Background = new SolidColorBrush(Color.FromArgb(255, (byte)(red), (byte)(green), (byte)(blue)));
item.Content = "#FF" + red.ToString("X2") + green.ToString("X2") + blue.ToString("X2");
cmbColors.Items.Add(item);
}
}
}
}
int interval = 120;
List<Color> colors = new List<Color>();
for (int red = 0; red < 255; red += interval)
{
for (int green = 0; green < 255; green += interval)
{
for (int blue = 0; blue < 255; blue += interval)
{
if (red > 150 | blue > 150 | green > 150 ) //to make sure color is not too dark
{
colors.Add(Color.FromARGB(Color.FromArgb(255, (byte)(red), (byte)(green), (byte)(blue));
}
}
}
}
var sortedColors = colors.OrderBy(c => c.GetHue())
.ThenBy(c => c.GetSaturation())
.ThenBy(c => c.GetBrightness());
foreach (Color c in sortedColors)
{
ComboBoxItem item = new ComboBoxItem {
Background = new SolidColorBrush(c),
Content = string.Format("#{0:X8}", c.ToArgb())
};
cmbColors.Items.Add(item);
}
int区间=120;
用于(整数红色=0;红色<255;红色+=间隔)
{
用于(整数绿色=0;绿色<255;绿色+=间隔)
{
对于(整数蓝色=0;蓝色<255;蓝色+=间隔)
{
如果(红色>150 |蓝色>150 |绿色>150)//确保颜色不太暗
{
ComboBoxItem=新ComboBoxItem();
item.Background=新的SolidColorBrush(颜色来自argb(255,(字节)(红色),(字节)(绿色),(字节)(蓝色));
item.Content=“#FF”+红色ToString(“X2”)+绿色ToString(“X2”)+蓝色ToString(“X2”);
cmbColors.Items.Add(item);
}
}
}
}
这使得这里有点像:
你们可以看到我有颜色对,看起来有点奇怪,有人有更好的主意吗?(我使用wpf)您的请求是主观的(“有点奇怪”不是一个措辞准确的问题!),但按色调对它们进行排序看起来是这样的:
int interval = 120;
for (int red = 0; red < 255; red += interval)
{
for (int green = 0; green < 255; green += interval)
{
for (int blue = 0; blue < 255; blue += interval)
{
if (red > 150 | blue > 150 | green > 150 ) //to make sure color is not too dark
{
ComboBoxItem item = new ComboBoxItem();
item.Background = new SolidColorBrush(Color.FromArgb(255, (byte)(red), (byte)(green), (byte)(blue)));
item.Content = "#FF" + red.ToString("X2") + green.ToString("X2") + blue.ToString("X2");
cmbColors.Items.Add(item);
}
}
}
}
int interval = 120;
List<Color> colors = new List<Color>();
for (int red = 0; red < 255; red += interval)
{
for (int green = 0; green < 255; green += interval)
{
for (int blue = 0; blue < 255; blue += interval)
{
if (red > 150 | blue > 150 | green > 150 ) //to make sure color is not too dark
{
colors.Add(Color.FromARGB(Color.FromArgb(255, (byte)(red), (byte)(green), (byte)(blue));
}
}
}
}
var sortedColors = colors.OrderBy(c => c.GetHue())
.ThenBy(c => c.GetSaturation())
.ThenBy(c => c.GetBrightness());
foreach (Color c in sortedColors)
{
ComboBoxItem item = new ComboBoxItem {
Background = new SolidColorBrush(c),
Content = string.Format("#{0:X8}", c.ToArgb())
};
cmbColors.Items.Add(item);
}
int区间=120;
列表颜色=新列表();
用于(整数红色=0;红色<255;红色+=间隔)
{
用于(整数绿色=0;绿色<255;绿色+=间隔)
{
对于(整数蓝色=0;蓝色<255;蓝色+=间隔)
{
如果(红色>150 |蓝色>150 |绿色>150)//确保颜色不太暗
{
Add(Color.FromARGB(Color.FromARGB(255,(字节)(红色),(字节)(绿色),(字节)(蓝色));
}
}
}
}
var sortedColors=colors.OrderBy(c=>c.GetHue())
.ThenBy(c=>c.GetSaturation())
.ThenBy(c=>c.GetBrightness());
foreach(分类颜色中的c色)
{
ComboBoxItem=新建ComboxItem{
背景=新的SolidColorBrush(c),
Content=string.Format(“#{0:X8}”,c.ToArgb())
};
cmbColors.Items.Add(item);
}
如果这看起来不够美观,请尝试排列
GetHue
、GetSaturation
和GetBrightness
调用,直到您满意为止。考虑按色调而不是RGB值对颜色进行排序。这样,颜色之间的过渡将不那么刺耳。这有什么奇怪的地方吗?使用?@S如何RirAMaSkTiffle,问某人是否是色盲,我认为这并不是粗鲁的,但是如果你认为是这样的话,请道歉。你能看到绿色/蓝色中间的紫色颜色吗?还是黄色“跳跃”成粉红色的方式,而不是逐渐褪色?这就是我们所说的。“谢里丹,我的第一语言不是英语。也许这就是我觉得这很冒犯的原因。NVM。所以op的意思是他们被搞混了,对吧?