Im doing this to create the file and save to it:
w = new StreamWriter(_outputDir + "\\" + averagesListTextFileDirectory + "\\" + averagesListTextFile + ".txt", false, Encoding.ASCII);
w.WriteLine("DANNY VIDEO META DATA\r\nFORMAT VERSION:1.00\r\nSOURCE: " + "<" + averagesListTextFile + ">" + "\r\nDATA: ");
for (int i = 0; i < averages.Count; i++)
{
w.WriteLine(averages[i]);
}
w.WriteLine("DATA");
w.Close();
But now i want to save to the file the values from a List wich in each index have another array of values. Like:
[0] 123 33 44 55 66…
[1] 33 44 565 66…
In each index there are 256 values.
I want the text file to look like that after DATA:
The next line will be something like:
Frame Number 1: 123 33 44 55 66
Frame Number 2: 33 44 565 66
So each line will be with 256 values.
This format.
Now the format of the file is like this:
DANNY VIDEO META DATA
FORMAT VERSION:1.00
SOURCE:
DATA:
15.1199916409607
13.7612831147295
13.746730806327
13.2768227559145
Now i want to make that when i read the values from the List the format will be like this:
DANNY VIDEO META DATA
FORMAT VERSION:1.00
SOURCE:
DATA:Frame Number 1: 123 33 44 55 66
Frame Number 2: 33 44 565 66
The question is how do i read the List that each index contain the 256 values and how do i write it to the text file ?
This is how i tried to do it:
private void WriteHistograms() // For automatic mode only for now
{
HistogramsFile = new StreamWriter(_outputDir + "\\" + averagesListTextFileDirectory + "\\" + "Histograms.txt", false, Encoding.ASCII);
HistogramsFile.WriteLine("DANNY VIDEO META DATA\r\nFORMAT VERSION:1.00\r\nSOURCE: " + "<" + averagesListTextFile + ">" + "\r\nDATA: ");
foreach (long[] array in Histograms)
{
foreach (long value in array)
{
frameNumber++;
HistogramsFile.WriteLine("Frame Number " + frameNumber + " : " + value);
}
}
HistogramsFile.WriteLine("DATA");
HistogramsFile.Close();
The result is a 25MB file size ! And here is example of the text file format:
DANNY VIDEO META DATA
FORMAT VERSION:1.00
SOURCE: <MVI_2483.AVI_Automatic>
DATA:
Frame Number 1 : 5977
Frame Number 2 : 40775
Frame Number 3 : 174395
Frame Number 4 : 305855
Frame Number 5 : 265805
Frame Number 6 : 212232
Frame Number 7 : 153333
Frame Number 8 : 99743
Frame Number 9 : 62334
Frame Number 10 : 41018
Frame Number 11 : 27381
Frame Number 12 : 21403
Frame Number 13 : 18324
In the end i see Frame Numbers:
Frame Number 973822 : 666
Frame Number 973823 : 1118
Frame Number 973824 : 0
Now sure why the last one is 0 and why 973824 frames while in fact there were about 3800 frames only.
So the file size is logic 25MB ? And format i wanted it to be is like:
Frame Number 1: 33 44 55 66 77 88 ……( 256 values in this line )
Frame Number 2: 22 33 12 3 44 55 …….( 256 values in this line )
And so on.
The List Histograms is type of wich in every index there are 256 indexs in each one a number:
[0] have: [1] 23 [2] 22 [3] 44 and so on
[1] have: [1] 12 [2] 13 [3] 21 and so on
So whats wrong ?
You will need a nested for loop in your original one:
This will allow you to iterate over your List of arrays. In general you would follow this type of loop for most 2 dimensional data structures.
Edit: If you want to print out each array on a seperate line you will need to modify the loop as follows:
This will produce the following: