How can i update the picturebox1 image according to the myTrackPanelss1.trackBar1 ?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Untill now i used _fi wich is FileInfo and GetFiles to get the files from the hard disk and used the trackBar1 and picturebox1 and updated them according to the _fi

Now in the bottom of the code of Form1 i created a list inside the function DothresholdCheck()
And in the bottom of this function im updating the myTrackPanelss1.trackBar1 and now i want to update the pictureBox1 according to the trackBar1 in this function and show the images from the list inside this function the list name is myNumbers and i used
string t there in the function to format the numbers in the list to files names.

So how can i change all the places in the code i used the _fi ( FileInfo ) and use the list and the trackBar1 from this function ?


And this is the complete Form1 code:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using Polkan.DataSource;
<span style="color:Blue; using System.IO;
<span style="color:Blue; using unfreez_wrapper;
<span style="color:Blue; using WindowsFormsApplication1;
<span style="color:Blue; using DannyGeneral;
<span style="color:Blue; using System.Text.RegularExpressions;

<span style="color:Blue; namespace Extracting_Frames
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form1 : Form
{
<span style="color:Blue; string subDirectoryName;
Options_Menu om;
<span style="color:Blue; public <span style="color:Blue; string _outputDir;
<span style="color:Blue; static <span style="color:Blue; string settings_dir;
<span style="color:Blue; static <span style="color:Blue; string settings_file;
<span style="color:Blue; static OptionsFile setting_file;
<span style="color:Blue; static <span style="color:Blue; string path_settings;
<span style="color:Blue; bool isNumericChanged = <span style="color:Blue; false;
<span style="color:Blue; int counter= 0;
<span style="color:Blue; string averagesListTextFileDirectory;
<span style="color:Blue; string averagesListTextFile;
StreamWriter w;
OpenFileDialog openFileDialog1;
<span style="color:Blue; int Hrs = 0; <span style="color:Green; //number of hours
<span style="color:Blue; int Min = 0; <span style="color:Green; //number of Minutes
<span style="color:Blue; int Sec = 0; <span style="color:Green; //number of Sec
<span style="color:Blue; int timeElapsed;
WmvAdapter f;
<span style="color:Green; //outputDir
<span style="color:Green; //= @"d:Frames";//Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ffff");
<span style="color:Green; //moviefile
<span style="color:Blue; private <span style="color:Blue; string _videoFile;<span style="color:Green; // = @"d:Lightnings Israel 03042011 Youtube4Down.com.avi";//@"D:Weather_MoviesMVI_1939.avi";//Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "DSCF0910.AVI");
FileInfo[] _fi = <span style="color:Blue; null;
<span style="color:Blue; delegate <span style="color:Blue; void del1(<span style="color:Blue; object sender, ProgressEventArgs e);
<span style="color:Blue; delegate <span style="color:Blue; void del2(<span style="color:Blue; object sender, EventArgs e);
<span style="color:Blue; delegate <span style="color:Blue; void del3(<span style="color:Blue; object sender, FrameCountEventArgs e);

<span style="color:Green; //Controls
<span style="color:Blue; private System.Windows.Forms.Button button1 = <span style="color:Blue; new System.Windows.Forms.Button();
<span style="color:Blue; private System.Windows.Forms.PictureBox pictureBox1 = <span style="color:Blue; new System.Windows.Forms.PictureBox();
<span style="color:Blue; private System.Windows.Forms.ProgressBar progressBar1 = <span style="color:Blue; new System.Windows.Forms.ProgressBar();
<span style="color:Blue; private System.Windows.Forms.Label label2 = <span style="color:Blue; new System.Windows.Forms.Label();
<span style="color:Blue; private List<<span style="color:Blue; int> _fts;

<span style="color:Blue; public Form1()
{
InitializeComponent();
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Visible = <span style="color:Blue; true;
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
path_settings = Path.GetDirectoryName(Application.LocalUserAppDataPath);
settings_file = <span style="color:#A31515; "\settings.txt";
settings_dir = path_settings + <span style="color:#A31515; @"settings";
<span style="color:Blue; if (Directory.Exists(settings_dir))
{
}
<span style="color:Blue; else
{
Directory.CreateDirectory(settings_dir);
}
<span style="color:Blue; if (!File.Exists(settings_dir + settings_file))
{
File.Create(settings_dir + settings_file);
}
setting_file = <span style="color:Blue; new OptionsFile(settings_dir + settings_file);
label18.Text = Options_DB.get_outputDir();
_outputDir = Options_DB.get_outputDir();
<span style="color:Blue; if (_outputDir == <span style="color:Blue; null)
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; try
{
StreamWriter sw = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "accessdenied.txt");
sw.Close();
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
_videoFile = Options_DB.get_loadedVideo();
numericUpDown1.Value = Options_DB.Get_thres();
DirectoryInfo info = <span style="color:Blue; new DirectoryInfo(_videoFile);
<span style="color:Blue; string dirName = info.Name;
averagesListTextFileDirectory = dirName;
averagesListTextFile = dirName;
subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
Directory.CreateDirectory(subDirectoryName);
<span style="color:Blue; if (_videoFile == <span style="color:Blue; null)
{
button1.Enabled = <span style="color:Blue; false;
}
<span style="color:Blue; else
{
button1.Enabled = <span style="color:Blue; true;
label13.Text = _videoFile;
label13.Visible = <span style="color:Blue; true;
label6.Visible = <span style="color:Blue; true;
}
numericUpDown1.Enabled = <span style="color:Blue; false;
openFileDialog1 = <span style="color:Blue; new OpenFileDialog();
timeElapsed = 0;
label1.Visible = <span style="color:Blue; false;
label2.Visible = <span style="color:Blue; false;
label3.Visible = <span style="color:Blue; false;
label4.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
label11.Visible = <span style="color:Blue; false;
label12.Visible = <span style="color:Blue; false;
label10.Text = <span style="color:#A31515; "00:00:00";
<span style="color:Green; //label13.Text = "50%";
checkBox2.Enabled = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;

<span style="color:Blue; if (Directory.Exists(_outputDir))
{
_fi = <span style="color:Blue; new DirectoryInfo(_outputDir).GetFiles();
myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;

<span style="color:Blue; if ( myTrackPanelss1.trackBar1.Maximum > 0)
{
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //checkBox2.Enabled = true;
}
<span style="color:Blue; if (_fi.Length >= 0)
{
label15.Text = _fi.Length.ToString();
label15.Visible = <span style="color:Blue; true;
}
}

<span style="color:Blue; if (!File.Exists(_videoFile))
{
button1.Enabled = <span style="color:Blue; false;

}
<span style="color:Blue; else
{
button1.Enabled = <span style="color:Blue; true;
}
DoThresholdCheck();
<span style="color:Green; //Init();
}

<span style="color:Blue; private <span style="color:Blue; void Init()
{
<span style="color:Green; //
<span style="color:Green; // button1
<span style="color:Green; //
<span style="color:Blue; this.button1.Location = <span style="color:Blue; new System.Drawing.Point(725, 382);
<span style="color:Blue; this.button1.Name = <span style="color:#A31515; "button1";
<span style="color:Blue; this.button1.Size = <span style="color:Blue; new System.Drawing.Size(75, 23);
<span style="color:Blue; this.button1.TabIndex = 0;
<span style="color:Blue; this.button1.Text = <span style="color:#A31515; "button1";
<span style="color:Blue; this.button1.UseVisualStyleBackColor = <span style="color:Blue; true;
<span style="color:Blue; this.button1.Click += <span style="color:Blue; new System.EventHandler(<span style="color:Blue; this.button1_Click);
<span style="color:Green; //
<span style="color:Green; // pictureBox1
<span style="color:Green; //
<span style="color:Blue; this.pictureBox1.Location = <span style="color:Blue; new System.Drawing.Point(204, 12);
<span style="color:Blue; this.pictureBox1.Name = <span style="color:#A31515; "pictureBox1";
<span style="color:Blue; this.pictureBox1.Size = <span style="color:Blue; new System.Drawing.Size(406, 278);
<span style="color:Blue; this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
<span style="color:Blue; this.pictureBox1.TabIndex = 1;
<span style="color:Blue; this.pictureBox1.TabStop = <span style="color:Blue; false;
<span style="color:Green; //
<span style="color:Green; // trackBar1
<span style="color:Green; //
myTrackPanelss1.trackBar1.Location = <span style="color:Blue; new System.Drawing.Point(12, 307);
myTrackPanelss1.trackBar1.Name = <span style="color:#A31515; "trackBar1";
myTrackPanelss1.trackBar1.Size = <span style="color:Blue; new System.Drawing.Size(788, 45);
myTrackPanelss1.trackBar1.TabIndex = 2;
<span style="color:Green; //
<span style="color:Green; // label1
<span style="color:Green; //
<span style="color:Blue; this.label1.AutoSize = <span style="color:Blue; true;
<span style="color:Blue; this.label1.Location = <span style="color:Blue; new System.Drawing.Point(12, 392);
<span style="color:Blue; this.label1.Name = <span style="color:#A31515; "label1";
<span style="color:Blue; this.label1.Size = <span style="color:Blue; new System.Drawing.Size(35, 13);
<span style="color:Blue; this.label1.TabIndex = 3;
<span style="color:Blue; this.label1.Text = <span style="color:#A31515; "label1";
<span style="color:Green; //
<span style="color:Green; // progressBar1
<span style="color:Green; //
<span style="color:Blue; this.progressBar1.Location = <span style="color:Blue; new System.Drawing.Point(15, 346);
<span style="color:Blue; this.progressBar1.Name = <span style="color:#A31515; "progressBar1";
<span style="color:Blue; this.progressBar1.Size = <span style="color:Blue; new System.Drawing.Size(785, 23);
<span style="color:Blue; this.progressBar1.TabIndex = 4;
<span style="color:Green; //
<span style="color:Green; // label2
<span style="color:Green; //
<span style="color:Blue; this.label2.AutoSize = <span style="color:Blue; true;
<span style="color:Blue; this.label2.Location = <span style="color:Blue; new System.Drawing.Point(398, 392);
<span style="color:Blue; this.label2.Name = <span style="color:#A31515; "label2";
<span style="color:Blue; this.label2.Size = <span style="color:Blue; new System.Drawing.Size(35, 13);
<span style="color:Blue; this.label2.TabIndex = 3;
<span style="color:Blue; this.label2.Text = <span style="color:#A31515; "label1";

<span style="color:Blue; this.ClientSize = <span style="color:Blue; new System.Drawing.Size(829, 430);
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.progressBar1);
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.label2);
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.label1);
<span style="color:Blue; this.Controls.Add( myTrackPanelss1.trackBar1);
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.pictureBox1);
<span style="color:Blue; this.Controls.Add(<span style="color:Blue; this.button1);
}

<span style="color:Green; //go
<span style="color:Blue; private <span style="color:Blue; void button1_Click(<span style="color:Blue; object sender, EventArgs e)
{
Start(<span style="color:Blue; false);
}

<span style="color:Blue; private <span style="color:Blue; void Start(<span style="color:Blue; bool secondpass)
{
SetPicture(-1);
<span style="color:Blue; if (Directory.Exists(_outputDir) && secondpass == <span style="color:Blue; false)
{
<span style="color:Green; /*if (MessageBox.Show("Directory exists, delete?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != System.Windows.Forms.DialogResult.Yes)
{
MessageBox.Show("aborted.");
return;
//throw new Exception("User aborted");
}*/

<span style="color:Green; //Directory.Delete(_outputDir, true);
<span style="color:Green; //Directory.CreateDirectory(_outputDir);
}
<span style="color:Blue; else
{
Directory.CreateDirectory(_outputDir);
}
<span style="color:Blue; string subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
Directory.CreateDirectory(subDirectoryName);
f = <span style="color:Blue; new WmvAdapter(_videoFile,
Path.Combine(subDirectoryName));

f.Secondpass = secondpass;
f.FramesToSave = _fts;

f.FrameCountAvailable += <span style="color:Blue; new WmvAdapter.FrameCountEventHandler(f_FrameCountAvailable);
f.StatusChanged += <span style="color:Blue; new WmvAdapter.EventHandler(f_StatusChanged);
f.ProgressChanged += <span style="color:Blue; new WmvAdapter.ProgressEventHandler(f_ProgressChanged);

<span style="color:Blue; this.Text = <span style="color:#A31515; "Working...";
label5.Visible = <span style="color:Blue; true;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
Hrs = 0; <span style="color:Green; //number of hours
Min = 0; <span style="color:Green; //number of Minutes
Sec = 0; <span style="color:Green; //number of Sec
timeElapsed = 0;
label10.Text = <span style="color:#A31515; "00:00:00";
label11.Visible = <span style="color:Blue; false;
label12.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.checkBox2.Enabled = <span style="color:Blue; false;
<span style="color:Blue; this.checkBox1.Enabled = <span style="color:Blue; false;
timer1.Start();
<span style="color:Green; //this.Enabled = false;
label2.Text = <span style="color:#A31515; "";
label1.Visible = <span style="color:Blue; true;
label2.Visible = <span style="color:Blue; true;
label3.Visible = <span style="color:Blue; true;
label4.Visible = <span style="color:Blue; true;
f.Start();
}


<span style="color:Green; /* private void Start(bool secondpass)
{
SetPicture(-1);

if (Directory.Exists(_outputDir))
{
//Directory.Delete(_outputDir, true);
//Directory.CreateDirectory(_outputDir);
}
else
{
Directory.CreateDirectory(_outputDir);
}


f.Secondpass = secondpass;
f.FramesToSave = _fts;

f.FrameCountAvailable += new WmvAdapter.FrameCountEventHandler(f_FrameCountAvailable);
f.StatusChanged += new WmvAdapter.EventHandler(f_StatusChanged);
f.ProgressChanged += new WmvAdapter.ProgressEventHandler(f_ProgressChanged);
label1.Visible = true;
label2.Visible = true;
label3.Visible = true;
label4.Visible = true;
timeElapsed = 0;
timer1.Start();
this.Text = "Working...";
//this.Enabled = false;
f.Start();
}*/

<span style="color:Blue; private <span style="color:Blue; void SetPicture(<span style="color:Blue; int indx)
{
<span style="color:Blue; if (_fi == <span style="color:Blue; null)
{
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
<span style="color:Blue; if (indx >= 0 && indx <= myTrackPanelss1.trackBar1.Maximum && _fi.Length > indx)
{
<span style="color:Blue; try
{
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Blue; using (FileStream fs = <span style="color:Blue; new FileStream(_fi[indx].FullName, FileMode.Open))
{
<span style="color:Blue; this.label8.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label9.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label9.Text = _fi[indx].FullName;
Image img = <span style="color:Blue; null;
Bitmap bmp = <span style="color:Blue; null;
Image imgOLd = <span style="color:Blue; null;

<span style="color:Blue; try
{
label5.Visible = <span style="color:Blue; false;

img = Image.FromStream(fs);
bmp = <span style="color:Blue; new Bitmap(img);

imgOLd = <span style="color:Blue; this.pictureBox1.Image;
<span style="color:Blue; this.pictureBox1.Image = bmp;
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
imgOLd.Dispose();

img.Dispose();
img = <span style="color:Blue; null;
}
<span style="color:Blue; catch
{
<span style="color:Blue; if (img != <span style="color:Blue; null)
img.Dispose();
<span style="color:Blue; if (bmp != <span style="color:Blue; null)
bmp.Dispose();
<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
imgOLd.Dispose();
}
}
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
}
<span style="color:Blue; else
{
Image imgOLd = <span style="color:Blue; this.pictureBox1.Image;
<span style="color:Green; //this.pictureBox1.Image = null;

<span style="color:Blue; if (imgOLd != <span style="color:Blue; null)
{
imgOLd.Dispose();
imgOLd = <span style="color:Blue; null;
}

Application.DoEvents();
}
}
}

<span style="color:Blue; void f_StatusChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del2(f_StatusChanged), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
WmvAdapter f = (WmvAdapter)sender;
List<<span style="color:Blue; double> averages = f.AveragesList;
<span style="color:Blue; bool secondPass = f.Secondpass;

<span style="color:Green; //free the resources
f.Dispose();

<span style="color:Blue; this.progressBar1.Value = <span style="color:Blue; this.progressBar1.Maximum;

<span style="color:Blue; if (!secondPass)
{
<span style="color:Green; //do the second pass processing
DoCheckResults(_outputDir , averages);
w = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "\" + averagesListTextFileDirectory + "\<span style="color:#A31515; " + averagesListTextFile + ".txt",<span style="color:Blue; false,Encoding.ASCII);
w.WriteLine(<span style="color:#A31515; "DANNY VIDEO META DATArnFORMAT VERSION:1.00rnSOURCE: " + <span style="color:#A31515; "<" + averagesListTextFile + <span style="color:#A31515; " + <span style="color:#A31515; "rnDATA: ");

<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < averages.Count; i++)
{
w.WriteLine(averages);
}
w.WriteLine(<span style="color:#A31515; "DATA");
w.Close();
<span style="color:Blue; this.progressBar1.Value = 0;

Start(<span style="color:Blue; true);
}
<span style="color:Blue; else
{
<span style="color:Blue; this.Text = <span style="color:#A31515; "Done";
<span style="color:Blue; this.button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //this.checkBox2.Enabled = true;
<span style="color:Blue; this.checkBox1.Enabled = <span style="color:Blue; true;
<span style="color:Green; //this.Enabled = true;
timer1.Stop();
<span style="color:Blue; this.progressBar1.Value = 0;
<span style="color:Blue; this.progressBar1.Enabled = <span style="color:Blue; false;

<span style="color:Blue; this.label2.Visible = <span style="color:Blue; false;
<span style="color:Blue; this.label4.Visible = <span style="color:Blue; false;
<span style="color:Blue; if (Directory.Exists(_outputDir))
{
_fi = <span style="color:Blue; new DirectoryInfo(_outputDir).GetFiles();
myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1;

<span style="color:Blue; if ( myTrackPanelss1.trackBar1.Maximum > 0)
{
SetPicture(0);
<span style="color:Green; //myTrackPanelss1.trackBar1.Scroll += new EventHandler(trackBar1_Scroll);
}
}
label11.Visible = <span style="color:Blue; true;
label12.Text = f.FramesToSave.Count.ToString();
label12.Visible = <span style="color:Blue; true;
}
}
}

<span style="color:Blue; private <span style="color:Blue; void DoCheckResults(<span style="color:Blue; string outputDir, List<<span style="color:Blue; double> averages)
{
<span style="color:Blue; double max = averages.Max();
<span style="color:Blue; double min = averages.Min();

_fts = <span style="color:Blue; new List<<span style="color:Blue; int>();

<span style="color:Blue; if (Directory.Exists(outputDir))
{
FileInfo[] allFiles = <span style="color:Blue; new DirectoryInfo(outputDir).GetFiles();

<span style="color:Blue; double thershold = (<span style="color:Blue; double)numericUpDown1.Value;
<span style="color:Blue; double max_min_threshold = (thershold/100) * (max-min) + min;
<span style="color:Green; //label13.Text = max_min_threshold.ToString();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < averages.Count; i++)
{
<span style="color:Blue; if (averages >= max_min_threshold)
{
_fts.Add(i);

}
}
}
}


<span style="color:Blue; void f_ProgressChanged(<span style="color:Blue; object sender, ProgressEventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del1(f_ProgressChanged), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; if (e.FrameID < <span style="color:Blue; this.progressBar1.Maximum)
<span style="color:Blue; this.progressBar1.Value = e.FrameID;

<span style="color:Blue; this.label2.Text = e.FrameID.ToString();
}
}

<span style="color:Blue; void f_FrameCountAvailable(<span style="color:Blue; object sender, FrameCountEventArgs e)
{
<span style="color:Blue; if (InvokeRequired)
{
<span style="color:Blue; this.Invoke(<span style="color:Blue; new del3(f_FrameCountAvailable), <span style="color:Blue; new <span style="color:Blue; object[] { <span style="color:Blue; null, e });
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; this.progressBar1.Maximum = (<span style="color:Blue; int)e.FrameCount;
<span style="color:Blue; this.label1.Visible = <span style="color:Blue; true;
<span style="color:Blue; this.label3.Text = e.FrameCount.ToString();
<span style="color:Blue; this.progressBar1.Enabled = <span style="color:Blue; true;
}
}

<span style="color:Blue; void trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
SetPicture( myTrackPanelss1.trackBar1.Value);
}

<span style="color:Blue; private <span style="color:Blue; void loadToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; string directoryName = <span style="color:#A31515; "";
<span style="color:Blue; string file1 = <span style="color:#A31515; "";
DialogResult result1; <span style="color:Gray; ///<span style="color:Green; // To fix problem with timer1 wich is stop when getting inside the debugmode after the first time \\\\\
result1 = <span style="color:Blue; new DialogResult();
openFileDialog1.Title = <span style="color:#A31515; "Select a vide ofile to load";
openFileDialog1.InitialDirectory = "c:\";
openFileDialog1.FileName = <span style="color:Blue; null;
openFileDialog1.Filter = <span style="color:#A31515; "Video File|*.mov;*.avi;*.mp4|Mov Avi Or MP4|*.mov;*.avi;*.mp4";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = <span style="color:Blue; true;
result1 = openFileDialog1.ShowDialog();
<span style="color:Blue; if (result1 == DialogResult.OK)
{
file1 = openFileDialog1.FileName;
_videoFile = file1;
<span style="color:Green; //label3.Text = f.framesCounts().ToString();
Options_DB.set_loadedVideo(_videoFile);
label1.Visible = <span style="color:Blue; true;
button1.Enabled = <span style="color:Blue; true;
DirectoryInfo inf = <span style="color:Blue; new DirectoryInfo(openFileDialog1.FileName);
directoryName = inf.Name;
label6.Visible = <span style="color:Blue; true;
label13.Visible = <span style="color:Blue; true;
label13.Text = directoryName;
averagesListTextFileDirectory = directoryName;
averagesListTextFile = directoryName;
<span style="color:Blue; string subDirectoryName = _outputDir + "\" + averagesListTextFileDirectory;
Directory.CreateDirectory(subDirectoryName);
<span style="color:Green; //f = new WmvAdapter(_videoFile,
<span style="color:Green; //Path.Combine(subDirectoryName));

}
<span style="color:Blue; if (result1 == DialogResult.Cancel)
{
<span style="color:Blue; if (file1 == <span style="color:#A31515; "")
{

}
}
}

<span style="color:Blue; private <span style="color:Blue; void timer1_Tick(<span style="color:Blue; object sender, EventArgs e)
{
timeElapsed = timeElapsed + 1;
<span style="color:Green; //textBox2.Text = timeElapsed.ToString();
label10.Text = GetTime(timeElapsed);

}

<span style="color:Blue; public <span style="color:Blue; string GetTime(<span style="color:Blue; int Time)
{
<span style="color:Green; //Seconds
Sec = Time % 60;

<span style="color:Green; //Minutes
Min = ((Time - Sec) / 60) % 60;

<span style="color:Green; //Hours
Hrs = ((Time - (Sec + (Min * 60))) / 3600) % 60;

<span style="color:Blue; return Hrs.ToString(<span style="color:#A31515; "00") + <span style="color:#A31515; ":" +
Min.ToString(<span style="color:#A31515; "00") + <span style="color:#A31515; ":" +
Sec.ToString(<span style="color:#A31515; "00");
}

<span style="color:Blue; private <span style="color:Blue; void Form1_FormClosing(<span style="color:Blue; object sender, FormClosingEventArgs e)
{
<span style="color:Blue; if (MessageBox.Show(<span style="color:#A31515; "Are you Sure you want to Exit. Click Yes to Confirm and No to continue", <span style="color:#A31515; "WinForm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
e.Cancel = <span style="color:Blue; true;
}
<span style="color:Blue; else
{
e.Cancel = <span style="color:Blue; false;
Environment.Exit(0);
}
}

<span style="color:Blue; private <span style="color:Blue; void checkBox1_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox1.Checked)
{
numericUpDown1.Enabled = <span style="color:Blue; true;
}
}

<span style="color:Blue; private <span style="color:Blue; void numericUpDown1_ValueChanged(<span style="color:Blue; object sender, EventArgs e)
{
Options_DB.Set_thres(numericUpDown1.Value);
<span style="color:Green; //timer2.Start();
<span style="color:Green; /*if (isNumericChanged == true)
{
counter = 0;
isNumericChanged = false;
}*/
DoThresholdCheck();

}

<span style="color:Blue; private <span style="color:Blue; void checkBox2_CheckedChanged(<span style="color:Blue; object sender, EventArgs e)
{
<span style="color:Blue; if (checkBox2.Checked)
{
myTrackPanelss1.panel1.Visible = <span style="color:Blue; true;
SetPicture(0);
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(myTrackPanless1_trackBar1_Scroll);
SetPicture( myTrackPanelss1.trackBar1.Value);
<span style="color:Green; //createAnimatedGif();
}
<span style="color:Blue; else
{
myTrackPanelss1.panel1.Visible = <span style="color:Blue; false;
SetPicture(myTrackPanelss1.trackBar1.Value);
}
}

<span style="color:Blue; private <span style="color:Blue; void myTrackPanless1_trackBar1_Scroll(<span style="color:Blue; object sender, EventArgs e)
{
SetPicture(myTrackPanelss1.trackBar1.Value);
}

<span style="color:Blue; private <span style="color:Blue; void createAnimatedGif()
{
UnFreezWrapper u = <span style="color:Blue; new UnFreezWrapper();
List<<span style="color:Blue; string> l = <span style="color:Blue; new List<<span style="color:Blue; string>();
<span style="color:Blue; for (<span style="color:Blue; int i = myTrackPanelss1.Start; i <= myTrackPanelss1.End; i++)
{
l.Add(String.Format(<span style="color:#A31515; "{0}{1}", <span style="color:#A31515; "picture", i));
}
u.MakeGIF(l, <span style="color:#A31515; @"d:anima.gif", 8, <span style="color:Blue; true);
}

<span style="color:Blue; private <span style="color:Blue; void timer2_Tick(<span style="color:Blue; object sender, EventArgs e)
{
counter = counter + 1;
<span style="color:Blue; if (counter > 7)
{
isNumericChanged = <span style="color:Blue; true;
}

}

<span style="color:Blue; private <span style="color:Blue; void DoThresholdCheck()
{
List<<span style="color:Blue; int> f;
List<<span style="color:Blue; string> fts;
<span style="color:Blue; const <span style="color:Blue; string D6 = <span style="color:#A31515; "000{0}.bmp";
<span style="color:Blue; if (Directory.Exists(subDirectoryName))
{
Regex numberPattern = <span style="color:Blue; new Regex(<span style="color:#A31515; @"^(d|.)+$");

List<<span style="color:Blue; double> myNumbers = <span style="color:Blue; new List<<span style="color:Blue; double>();
<span style="color:Blue; if (!File.Exists(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt"))
{
<span style="color:Blue; return;
}
<span style="color:Blue; else
{
<span style="color:Blue; using (StreamReader reader = <span style="color:Blue; new StreamReader(subDirectoryName + <span style="color:#A31515; "\" + averagesListTextFile + ".txt"))
{
<span style="color:Blue; string line;
<span style="color:Blue; while ((line = reader.ReadLine()) != <span style="color:Blue; null)
{
<span style="color:Blue; if (numberPattern.IsMatch(line))
{
<span style="color:Blue; double myLine = Convert.ToDouble(line);
myNumbers.Add(myLine);
}
}


<span style="color:Blue; double max = myNumbers.Max();
<span style="color:Blue; double min = myNumbers.Min();

f = <span style="color:Blue; new List<<span style="color:Blue; int>();
fts = <span style="color:Blue; new List<<span style="color:Blue; string>();

<span style="color:Blue; int counter = 0;
<span style="color:Blue; double thershold = (<span style="color:Blue; double)numericUpDown1.Value;
<span style="color:Blue; double max_min_threshold = (thershold / 100) * (max - min) + min;
<span style="color:Green; //label13.Text = max_min_threshold.ToString();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < myNumbers.Count; i++)
{
<span style="color:Blue; if (myNumbers >= max_min_threshold)
{
f.Add(i);
<span style="color:Blue; string t = i.ToString(<span style="color:#A31515; "D6") + <span style="color:#A31515; ".bmp";
<span style="color:Blue; if (File.Exists(subDirectoryName + "\" + t))
{
counter++;
button1.Enabled = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
myTrackPanelss1.trackBar1.Minimum = 0;


}
<span style="color:Blue; else
{
button1.Enabled = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
pictureBox1.Image = Properties.Resources.Weather_Michmoret;
label5.Visible = <span style="color:Blue; true;
<span style="color:Blue; break;
}

<span style="color:Green; //fts.Add(string.Format(D6, myNumbers));
}
}

}
myTrackPanelss1.trackBar1.Maximum = f.Count;
myTrackPanelss1.trackBar1.Value = f.Count;

myTrackPanelss1.trackBar1.Scroll += <span style="color:Blue; new EventHandler(trackBar1_Scroll);
<span style="color:Green; /* double max = averages.Max();
double min = averages.Min();

_fts = new List<int>();


FileInfo[] allFiles = new DirectoryInfo(outputDir).GetFiles();

double thershold = (double)numericUpDown1.Value;
double max_min_threshold = (thershold / 100) * (max - min) + min;
//label13.Text = max_min_threshold.ToString();
for (int i = 0; i < averages.Count; i++)
{
if (averages >= max_min_threshold)
{
_fts.Add(i);

}
}*/

}
}
<span style="color:Blue; else
{
button1.Enabled = <span style="color:Blue; true;
}
<span style="color:Green; // to save to a text file the list of values numbers above threshold and read this values from the text file to here and create a list by that \
<span style="color:Green; // this list here will update each time i change the threshold later on and if the list of numbers above threshold changed to use it again \
<span style="color:Green; // 50% 60 files to hard disk. create list of frames according to the threshold change \
<span style="color:Green; // the list of indexs will update each time i change the threshold \
<span style="color:Green; // if upload new file video to create this list of indexs if i have the averages list already \

<span style="color:Green; // to check the indexs of the new list if they exists on hard disk \
<span style="color:Green; // to check if file.exist to change the indexs to file names like on hard disk and check if its exist on hard disk \
<span style="color:Green; // using for \
<span style="color:Green; // if button beging process enable to check when click on it if the file exist on hard disk and if it si so to not extract it even if its above threshold \

}

<span style="color:Blue; private <span style="color:Blue; void optionsToolStripMenuItem_Click(<span style="color:Blue; object sender, EventArgs e)
{
om = <span style="color:Blue; new Options_Menu();
om.Show();
om.FormClosing += <span style="color:Blue; new FormClosingEventHandler(optionsMenu1_FormClosing);
optionsToolStripMenuItem.Enabled = <span style="color:Blue; false;
om.Location = <span style="color:Blue; new Point(0, 0);
om.tb.TextChanged += <span style="color:Blue; new EventHandler(tb_TextChanged);

}

<span style="color:Blue; private <span style="color:Blue; void optionsMenu1_FormClosing(<span style="color:Blue; object sender, FormClosingEventArgs e)
{
optionsToolStripMenuItem.Enabled = <span style="color:Blue; true;
}

<span style="color:Blue; private <span style="color:Blue; void tb_TextChanged(<span style="color:Blue; object sender, EventArgs e)
{
label18.Text = om.tb.Text;
<span style="color:Blue; if (om.enabledOrNot == <span style="color:Blue; true)
{
<span style="color:Blue; try
{
_outputDir = Options_DB.get_outputDir();
StreamWriter sw = <span style="color:Blue; new StreamWriter(_outputDir + <span style="color:#A31515; "accessdenied.txt");
sw.Close();
label19.ForeColor = Color.Red;
fileToolStripMenuItem.Enabled = <span style="color:Blue; true;
label19.Visible = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; true;
label15.Visible = <span style="color:Blue; true;
label8.Visible = <span style="color:Blue; true;
label9.Visible = <span style="color:Blue; true;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; true;
}
<span style="color:Blue; catch
{
label19.Visible = <span style="color:Blue; true;
label19.ForeColor = Color.Green;
label19.Text = <span style="color:#A31515; "The Selected Directory Is Access Denied";
fileToolStripMenuItem.Enabled = <span style="color:Blue; false;
label14.Visible = <span style="color:Blue; false;
label15.Visible = <span style="color:Blue; false;
label8.Visible = <span style="color:Blue; false;
label9.Visible = <span style="color:Blue; false;
myTrackPanelss1.trackBar1.Enabled = <span style="color:Blue; false;
<span style="color:Blue; return;
}
}
}
}
}


<span style="color:Green; // To check the numericupdown1 in valuechanged event if needed this event. And to make the list idead Adi messenger. \

<span style="color:Green; // To add a label that will be visible only if the output dir is not empty and it will show the number of files in the output dir \

<span style="color:Green; // To change that the output files names on hard disk will be with some order or names like: image000001.bmp, image000002.bmp...and so on \

<span style="color:Green; // To check label10 for some reason when making threshhold 0% itscopying all frames to hard disk but on the second time when setting threshhold to 63% even if it should copy only 59 frames
<span style="color:Green; // and i guess its realy copying 59 frames but its showing in label10 all the 0% frames 4873 maybe for some reason label10 showing the current files on the output dir.
<span style="color:Green; // So either to check label10 what its showing where in what places or either to delete the files each time a new process start \
[/code]
<br/>
Thanks. <hr class="sig danieli

View the full article
 
Back
Top