我一直在寻找一周以来如何创造这样的东西.
我有代码和for循环来创建每个Panel X,和Y coords和一切.每个Panel都是一个数组的一部分,从左上角的0开始到右上角的90结束,但我不关心它的完成情况以及它的面板和工作.颜色不需要相同,但类似的东西,以便我可以有一个全屏颜色选择器.如果有人知道一些代码采用一种特定的颜色并使其更亮十倍来设置面板backColor,使用Color.FromARGB或只是Color类,那么请帮助我.谢谢.
(这是我正在为Windows平板电脑制作的应用程序,并且是触摸屏.该应用程序的目的是全屏而不是它的Windows平板电脑,我必须自己制作颜色选择器,不能使用内置颜色对话框.)
为了获得最佳控制,我建议使用颜色计算功能.
那里有很多; 这是我用的一个:
Color HsvToRgb(double h, double S, double V)
{
/// Convert HSV to RGB
/// h is from 0d - 360d
/// s,v values are 0d - 1d
/// r,g,b values are 0 - 255
int hi = Convert.ToInt32(Math.Floor(hue / 60)) % 6;
double f = hue / 60 - Math.Floor(hue / 60);
value = value * 255;
int v = Convert.ToInt32(value);
int p = Convert.ToInt32(value * (1 - saturation));
int q = Convert.ToInt32(value * (1 - f * saturation));
int t = Convert.ToInt32(value * (1 - (1 - f) * saturation));
if (hi == 0) return Color.FromArgb(255, v, t, p);
else if (hi == 1) return Color.FromArgb(255, q, v, p);
else if (hi == 2) return Color.FromArgb(255, p, v, t);
else if (hi == 3) return Color.FromArgb(255, p, q, v);
else if (hi == 4) return Color.FromArgb(255, t, p, v);
else return Color.FromArgb(255, v, p, q);
}
Run Code Online (Sandbox Code Playgroud)
请注意输入范围!!
现在很容易Color在类级别设置一个数组:
int width = 10;
int height = 9;
Color[,] colors;
Run Code Online (Sandbox Code Playgroud)
填写它:
void loadColors()
{
colors = new Color[width, height];
// load greys
for (int i = 0; i < width; i++ ) colors[i, 0] = HsvToRgb(0f, 0f, 1f * i / width);
// load bright stripe:
for (int i = 0; i < width; i++) colors[i, 1] = HsvToRgb(i* 360f / width, 0.33f, 1f);
// load matrix:
for (int j = 2; j < height; j++)
for (int i = 0; i < width; i++)
colors[i, j] = HsvToRgb(i * 360f / width, 1f, 1f * (height - j + 2) / height);
}
Run Code Online (Sandbox Code Playgroud)
从中可以轻松设置BackColors您的Panels.
这是一个Form.Paint函数,我用来创建上面的截图:
private void Form1_Paint(object sender, PaintEventArgs e)
{
int w = ClientSize.Width / width;
int h = ClientSize.Height / height;
for (int j = 0; j < height; j++)
for (int i = 0; i < width; i++)
{
using (SolidBrush brush = new SolidBrush(colors[i,j]))
e.Graphics.FillRectangle(brush, i * w, j * h, w, h);
}
}
Run Code Online (Sandbox Code Playgroud)
当然,它就像更改两个数字以制作更精细的网格一样简单,这里是20x20:
还要注意色调的均匀间距不能很好地工作,因为人眼和我们常见的显示系统都不会对整个光谱中的色调变化同样敏感.
波长的明显差异从蓝绿色和黄色波长的约1 nm变化到10 nm以及更长的红色和更短的蓝色波长
但我们的显示器在创造不同的绿色色调方面做得非常差劲.
根据您的需要,使用经过调整的均匀间隔色调的改编列表可能会有所帮助.
使用这个单线:
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
int hue = (int) ((Bitmap)pictureBox1.Image).GetPixel(e.X, e.Y).GetHue();
}
Run Code Online (Sandbox Code Playgroud)
在上图中给出了一个这样的色调列表:
20 32 41 50 58 72 133 163 170 177 183 190 197 206 269 288 307 324 334 346
Run Code Online (Sandbox Code Playgroud)
我稍微修改了一下,也许是为了让我的显示器更好用:
List<int> hues = new List<int>
{ 20, 32, 41, 50, 58, 72, 133, 162, 180, 188, 195, 205, 215, 223, 246, 267, 288, 300, 320, 346 };
Run Code Online (Sandbox Code Playgroud)
并将上面的代码(保持宽度= 20)更改为
HsvToRgb(hues[i],..
Run Code Online (Sandbox Code Playgroud)
结果如下:
更新:我已经HsvToRgb通过大大简化的功能替换了该功能.
| 归档时间: |
|
| 查看次数: |
2758 次 |
| 最近记录: |