EDN Admin
Well-known member
The code:
<pre class="prettyprint private void loadHistogramFileToolStripMenuItem_Click(object sender, EventArgs e)
{
string file1 = "";
DialogResult result1; ///// To fix problem with timer1 wich is stop when getting inside the debugmode after the first time \\\\\
result1 = new DialogResult();
openFileDialog1.Title = "Select an histogram file to load";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = null;
openFileDialog1.Filter = "Histogram File|*.dat|All|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
result1 = openFileDialog1.ShowDialog();
if (result1 == DialogResult.OK)
{
HistogramLoadedFile = true;
automaticDone = false;
manualDone = false;
button2.Enabled = true;
checkBox1.Enabled = true;
file1 = openFileDialog1.FileName;
Options_DB.set_histogramFileDirectory(file1);
directoryName = Path.GetDirectoryName(file1);
label1.Visible = true;
button1.Enabled = true;
label6.Text = "Loaded Histogram File: ";
label6.Visible = true;
label13.Visible = true;
label13.Text = file1;
if (File.Exists(file1))
{
BinaryReader binReader =
new BinaryReader(File.Open(file1, FileMode.Open));
try
{
//byte[] testArray = new byte[3];
int pos = 0;
int length = (int)binReader.BaseStream.Length;
binReader.BaseStream.Seek(0, SeekOrigin.Begin);
while (pos < length)
{
long[] l = new long[256];
for (int i = 0; i < 256; i++)
{
if (pos < length)
l = binReader.ReadInt64();
else
break;
pos += sizeof(Int64);
}
list_of_histograms.Add(l);
}
}
catch
{
}
finally
{
binReader.Close();
}[/code]
The file on the hard disk is: histogramValues.dat the file size is 328kb.
But when its loading the file after loaded it im looking with a break point on the List(list_of_histograms) and see that there are 328 indexs in the List and the one i checked was index 164 wich is on the hard disk should be file: 000164.bmp and in index
164 there is an histogram 256 numbers but they are not the same as they were when i wrote the histogramValues.dat file to the hard disk.
This is how im writing the .dat file to the hard disk:
<pre class="prettyprint using (Bitmap resized_bmp = ResizeBitmap(bitmap, 100, 100))
{
resized_bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
resized_bmp.Save(Path.Combine(_outFolder, _frameId.ToString("D6") + ".bmp"), ImageFormat.Bmp);
string fname = Path.Combine(_outFolder, _frameId.ToString("D6") + ".bmp");
Bitmap b = new Bitmap(fname);
long[] HistogramsValues = Form1.GetHistogram(b);
if (histogramValuesList == null)
histogramValuesList = new List<long>(256);
histogramValuesList.AddRange(HistogramsValues);
using (BinaryWriter binWriter =
new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
for (int i = 0; i < histogramValuesList.Count; i++)
{
binWriter.Write(histogramValuesList[(int)i]);
}
binWriter.Close();
}
}[/code]
I used a breakpoint and stopped the program when the variable fname was on 164. Then i checked the histogram of fname 164(000164.bmp) and saw its writing to the file an histogram with numbers but now when i look on the List after reading/loading the file
i see in place 164 a different numbers.
And if i stopped the program on 164 fname = 000164.bmp why the file size is 328kb and why when reading it there are 328 indexs and not 164 ?
Again i used now a breakpoint and im looking on fname when its 000164.bmp then im looking on HistogramValues and see the 000164.bmp histogram numbers start from 0 and 1 2 0 low numbers in the first indexs but when im loading the same dat file i see in place
164 that it start with high numbers very high.
I cant figure out where is the problem.
<hr class="sig danieli
View the full article
<pre class="prettyprint private void loadHistogramFileToolStripMenuItem_Click(object sender, EventArgs e)
{
string file1 = "";
DialogResult result1; ///// To fix problem with timer1 wich is stop when getting inside the debugmode after the first time \\\\\
result1 = new DialogResult();
openFileDialog1.Title = "Select an histogram file to load";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = null;
openFileDialog1.Filter = "Histogram File|*.dat|All|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
result1 = openFileDialog1.ShowDialog();
if (result1 == DialogResult.OK)
{
HistogramLoadedFile = true;
automaticDone = false;
manualDone = false;
button2.Enabled = true;
checkBox1.Enabled = true;
file1 = openFileDialog1.FileName;
Options_DB.set_histogramFileDirectory(file1);
directoryName = Path.GetDirectoryName(file1);
label1.Visible = true;
button1.Enabled = true;
label6.Text = "Loaded Histogram File: ";
label6.Visible = true;
label13.Visible = true;
label13.Text = file1;
if (File.Exists(file1))
{
BinaryReader binReader =
new BinaryReader(File.Open(file1, FileMode.Open));
try
{
//byte[] testArray = new byte[3];
int pos = 0;
int length = (int)binReader.BaseStream.Length;
binReader.BaseStream.Seek(0, SeekOrigin.Begin);
while (pos < length)
{
long[] l = new long[256];
for (int i = 0; i < 256; i++)
{
if (pos < length)
l = binReader.ReadInt64();
else
break;
pos += sizeof(Int64);
}
list_of_histograms.Add(l);
}
}
catch
{
}
finally
{
binReader.Close();
}[/code]
The file on the hard disk is: histogramValues.dat the file size is 328kb.
But when its loading the file after loaded it im looking with a break point on the List(list_of_histograms) and see that there are 328 indexs in the List and the one i checked was index 164 wich is on the hard disk should be file: 000164.bmp and in index
164 there is an histogram 256 numbers but they are not the same as they were when i wrote the histogramValues.dat file to the hard disk.
This is how im writing the .dat file to the hard disk:
<pre class="prettyprint using (Bitmap resized_bmp = ResizeBitmap(bitmap, 100, 100))
{
resized_bmp.RotateFlip(RotateFlipType.Rotate180FlipX);
resized_bmp.Save(Path.Combine(_outFolder, _frameId.ToString("D6") + ".bmp"), ImageFormat.Bmp);
string fname = Path.Combine(_outFolder, _frameId.ToString("D6") + ".bmp");
Bitmap b = new Bitmap(fname);
long[] HistogramsValues = Form1.GetHistogram(b);
if (histogramValuesList == null)
histogramValuesList = new List<long>(256);
histogramValuesList.AddRange(HistogramsValues);
using (BinaryWriter binWriter =
new BinaryWriter(File.Open(fileName, FileMode.Create)))
{
for (int i = 0; i < histogramValuesList.Count; i++)
{
binWriter.Write(histogramValuesList[(int)i]);
}
binWriter.Close();
}
}[/code]
I used a breakpoint and stopped the program when the variable fname was on 164. Then i checked the histogram of fname 164(000164.bmp) and saw its writing to the file an histogram with numbers but now when i look on the List after reading/loading the file
i see in place 164 a different numbers.
And if i stopped the program on 164 fname = 000164.bmp why the file size is 328kb and why when reading it there are 328 indexs and not 164 ?
Again i used now a breakpoint and im looking on fname when its 000164.bmp then im looking on HistogramValues and see the 000164.bmp histogram numbers start from 0 and 1 2 0 low numbers in the first indexs but when im loading the same dat file i see in place
164 that it start with high numbers very high.
I cant figure out where is the problem.
<hr class="sig danieli
View the full article