-1
int numberofframesX = 0;
int numberofframesY = 0;
string framesX = "";
string framesY = "";
string X = "";
string Y = "";
string t = path + "\\" + fileName;
OptionsFile setting_file = new OptionsFile(t);
string XX = setting_file.GetKey("Number Of Frames X");
string YY = setting_file.GetKey("Number Of Frames Y");
numberofframesX = Convert.ToInt32(XX);
numberofframesY = Convert.ToInt32(YY);    

for (int i = 1; i < numberofframesX ; i++)
{
    X  = string.Format("Frame_X_{0} ", i);
    framesX = setting_file.GetKey(X);
    List<string> floatStrings = new List<string>(framesX.Split(new char[] { ',' }));
    List<float> test = new List<float>(  floatStrings.Select(tempStr => (float)Convert.ToDouble(tempStr)).ToList()); 
    wo1.woc.Point_X = test; 
}

我需要按照我的问题底部下面链接中的两个图像中显示的内容进行操作。woc index [0] 有两个浮点列表我需要在 Point_X 中将每个数字添加到 Point_X 中的索引中,例如第 1 帧是 Frame_X_1 所以右边的数字应该添加到 Point_X 索引然后在 woc[1] Frame_X_2 等等.....

这是文本文件(setting_file)

Frame_X_1 =323,332,322,332
Frame_Y_1 =206,212,218,203
Frame_X_2 =323,332,318,332
Frame_Y_2 =206,212,269,203
Frame_X_3 =323,332,318,332
Frame_Y_3 =206,212,269,203
Frame_X_4 =323,332,318,332
Frame_Y_4 =206,212,269,203
Frame_X_5 =323,332,318,332
Frame_Y_5 =206,212,269,203
Frame_X_6 =323,332,318,332
Frame_Y_6 =206,212,269,203
Frame_X_7 =323,332,318,332
Frame_Y_7 =206,212,269,203
Frame_X_8 =323,332,318,332
Frame_Y_8 =206,212,269,203
Number Of Frames X=4
Number Of Frames Y=4

这是 woc WireObjectCoordinates 类的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AnimationEditor
{
    class WireObjectCoordinates
    {
        public List<float> Point_X = new List<float>();
        public List<float> Point_Y = new List<float>();

        public WireObjectCoordinates()
        {
        }

        public WireObjectCoordinates(WireObjectCoordinates w)
        {
            Point_X.AddRange(w.Point_X);
            Point_Y.AddRange(w.Point_Y);
        }

        public void Set(WireObjectCoordinates w)
        {
            for (int i = 0; i < Point_X.Count; i++)
            {
                Point_X[i] = w.Point_X[i];
                Point_Y[i] = w.Point_Y[i];
            }
        }
    }
}

以及 setting_file(OptionsFile) 类中的 GetKey 函数:

/*----------------------------------------------------------
 * Function     : GetKey
 * Description  : gets the value of the key.
 * Parameters   : key
 * Return       : value of the key if key exist, null if not exist
 * --------------------------------------------------------*/
    public string GetKey(string key)
    {

      //  string value_of_each_key;
        string key_of_each_line;
        string line;
        int index;
        string key_value;
        key_value = null;

        sr = new StreamReader(Options_File);
        while (null != (line = sr.ReadLine()))
        {


            index = line.IndexOf("=");


           //    value_of_each_key = line.Substring(index+1);



            if (index >= 1)
            {
                key_of_each_line = line.Substring(0, index);
                if (key_of_each_line == key)
                {
                    key_value = line.Substring(key.Length + 1);
                }

            }
            else
            {
            }


        }
        sr.Close();
        return key_value;
    }

我现在添加了两张关于 WOC 和 Point_X 和 Point_Y 的图像:

http://imageshack.us/photo/my-images/515/imag0649b.jpg/ http://imageshack.us/photo/my-images/23/imag0648me.jpg/

4

1 回答 1

1

Sounds like you want to use a List<List<float>>. Or if your sets of floats are fixed, you could probably use List<float[]>

于 2012-07-19T15:53:59.197 回答