在MSchart中绘制CIE颜色空间

时间:2017-02-08 07:33:57

标签: c# mschart

我有一个6300 * 5数组:

  • 1,2 = CIE数据
  • 3,4,5 = S R G B

我应该如何在MsChart中绘制它?

enter image description here

1 个答案:

答案 0 :(得分:1)

您有几种选择:

  • DataPoints
  • 中添加Markers Colors Annotations
  • 添加xxxPaint
  • 使用其中一个FillElipse事件

只有6500点,您无法通过设置单个像素来填充该区域。因此,您最好对每个点使用Pre调用。

如果您使用PostPaint - 或ValueToPixelPosition事件,则需要使用AxisX / Y方法Minimum来计算CIE值的像素坐标。

无论如何,您为Maximum设置了AxesMarkers

此外,您还需要计算Annotations'或ClientSize'或者省略号'图表DataPoint Cie2DataPoint(float x, float y, float r, float g, float b) { var dp = new DataPoint(x, y); dp.Color = Color.FromArgb((int)(256 * r), (int)(256 * g),(int)(256 * b)); dp.MarkerColor = dp.Color; return dp; } 中的尺寸可以避免彩色区域中出现难看的间隙。

如果要使用DataPoints,请设置ChartType = Point并对每个数据使用此函数:

int MarkerSize(Chart chart, int count)
{
    return Math.Max(chart.ClientSize.Width, chart.ClientSize.Height )/ count + 1
}

void Rescale(Chart chart)
{
    Series s = chart3.Series[0];
    s.MarkerSize = MarkerSize(chart3, (int)Math.Sqrt(s.Points.Count));
}

以下是辅助函数的示例:

ChartArea

前者估计每个轴所需的绘图点数;你可能需要尝试一下。下一个假设这些点实际上是一个正方形;另外你只有一个private void chart3_Resize(object sender, EventArgs e) { Rescale (sender as Chart); }

这也应该针对您的数据进行修改!

我们需要在调整图表大小时重新调整大小:

Series s = chart3.Series[0];
s.ChartType = SeriesChartType.Point;
s.MarkerSize = 3;
for (int x = 0; x < 100; x++)
   for (int y = 0; y < 100; y++)
   {
        s.Points.Add(Cie2DataPoint(x/100f, y/100f, x/100f, y/100f, (x+y)/200f));
   }

ChartArea ca = chart3.ChartAreas[0];
ca.AxisX.Minimum = 0;
ca.AxisY.Minimum = 0;
ca.AxisX.Maximum = 1;
ca.AxisY.Maximum = 1;
ca.AxisX.Interval = 0.1f;
ca.AxisY.Interval = 0.1f;
ca.AxisX.LabelStyle.Format = "0.00";
ca.AxisY.LabelStyle.Format = "0.00";

Rescale(chart3);

以下是使用计算的数据集进行设置的示例。你应该循环遍历你的数据列表..:

foreach (DataGridViewCell cell in row.Cells) {
  cell.Style.BackColor = Color.Red;
}

结果:

enter image description here

从CIE颜色表中抓取约6k种颜色后,结果看起来相当粗糙,但基本上是正确的:

enter image description here

请注意,您可能需要以某种方式允许反转的y轴;我只是从0.9f中减去了我的y值。使用你自己的号码!

相关问题