0
我怎樣才能只序列化數據點?我想將DataPoints保存到一個文件中。數據點序列化
[Serializable]
class CIE
{
public List<DataPoint> CieDataPoint = new List<DataPoint>() ;
}
List<DataPoint> GetCieColorPoints(string filename, int count)
{
CIE cie = new CIE();
var data = new List<DataPoint>();
float cr = (float)Math.Sqrt(count);
using (Bitmap bmp = new Bitmap(filename))
{
int sx = (int)(bmp.Width/cr);
int sy = (int)(bmp.Height/cr);
float scx = 0.8f/bmp.Width;
float scy = 0.9f/bmp.Height;
for (int x = 0; x < bmp.Width; x += sx)
for (int y = 0; y < bmp.Height; y += sy)
{
Color c = bmp.GetPixel(x, y);
float b = c.GetBrightness();
if (b > 0.01f && b < 0.99f)
{
var dp = new DataPoint(x * scx, 0.9f - y * scy);
dp.Color = c;
dp.MarkerColor = dp.Color;
dp.MarkerStyle = MarkerStyle.Circle ;
data.Add(dp);
}
}
}
return data;
}
Cie.CieDataPoint = GetCieColorPoints("E:\\CIExy1931_T2.png", 125000);;
IFormatter formatter = new BinaryFormatter();
FileStream seryalization = new FileStream("CIEdata", FileMode.Create, FileAccess.Write);
formatter.Serialize(seryalization, Cie);
seryalization.Close();
錯誤 其他信息:類型 'System.Windows.Forms.DataVisualization.Charting.DataPoint' 在大會「System.Windows.Forms.DataVisualization,版本= 4.0.0.0,文化=中性公鑰= 31bf3856ad364e35 '未標記爲可序列化。
請出示DataPoint'的'定義。此外,[MSDN](https://msdn.microsoft.com/de-de/library/system.serializableattribute(v = vs.110).aspx)提供了一個如何使用「Serializable'屬性的例子。 – Codor
@Codor它是一個框架類型 - 「System.Windows.Forms.DataVisualization.Charting.DataPoint」。 –