Hello All,
I am trying to load images from a file path after saving them from a c328 camera. The camera part works but when I use a while loop it does not display on the picturebox. All of this is done when clicking a button. Any ideas?
private void Connect_Click(object sender, EventArgs e)
{
//Check if com port 1 is busy
if (serialPort1.IsOpen)
{
//if busy show it to user
Result.Text = "Com1 is busy. Close other application...";
Result.Refresh();
}
else
{
// if not open, open port
serialPort1.Open();
Result.Text = "Com1 opened successfully...";
Result.Refresh();
// take one picture
SYNC_Click();
Thread.Sleep(80);
JPEGSize_Click();
Thread.Sleep(80);
PackSize_Click();
Thread.Sleep(80);
SnapShot_Click();
Thread.Sleep(80);
Preview_Click();
Thread.Sleep(80);
Save_Click();//saves in this method the reference image
Connect.Enabled = false;
Disconnect.Enabled = true;
Thread.Sleep(5000);
while (true)
{
// pictureBox1.Dispose();
SYNC_Click();
Thread.Sleep(80);
JPEGSize_Click();
Thread.Sleep(80);
PackSize_Click();
Thread.Sleep(80);
SnapShot_Click();
Thread.Sleep(80);
Preview_Click();
Thread.Sleep(80);
Save_Click();//saves in this method the new image
Thread.Sleep(5000);
Connect.Enabled = false;
Disconnect.Enabled = true;
}
}
}
..........
private void Save_Click()
{
//Create new folder for the picture
if (!(File.Exists(@"c:\M_files\new_pics\ref.jpg")))
{
try
{
Image image = pictureBox1.Image;
image.Save("c:\\M_files\\new_pics\\ref.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (System.NullReferenceException de) //catch exceptions and just disconnect
{
serialPort1.Close();
Result.Text = "Com1 closed successfully...";
Result.Refresh();
Connect.Enabled = true;
Disconnect.Enabled = false;
}
}
else
{
pictureBox1.Invalidate();
pictureBox1.Update();
Image image = pictureBox1.Image;
image.Save("c:\\M_files\\new_pics\\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
MLApp.MLAppClass matlab = new MLApp.MLAppClass();
matlab.Execute("cd c:\\M_files"); //changes directory
matlab.Execute("jesse_script");
Thread.Sleep(5000);
pictureBox1.Image = Image.FromFile("c:\\M_files\\new_pics\\newmarked.jpg");
}
}