I am taking images with a machine vision camera and storing them into a folder. I want to show the saved image in a pictureBox before the next image is stored. My code is successfully showing the image in the pictureBox, however, there is a delay so i.e by the time image 10 is saved to the folder the GUI is only showing image 3. I am not sure how to increase the performance to allow the GUI to update in real time as I am taking images.
I think my problem may be due to using the png image to create the MemoryStream instead of the byte[] buffer (raw sensor data). I have attempted using the byte[] but I was not able to successfully populate the pictureBox.
This is my code:
// Grab a number of images.
for (int i = 0; i < num_images; ++i)
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
IGrabResult grabResult = camera.StreamGrabber.RetrieveResult(5000,
TimeoutHandling.ThrowException);
using (grabResult)
{
// Image grabbed successfully?
if (grabResult.GrabSucceeded)
{
buffer = grabResult.PixelData as byte[];
//ImageWindow.DisplayImage(0, grabResult);
file_extension = "Position_" + i + ".png";
image_filename = String.Concat(image_filepath, file_extension);
ImagePersistence.Save(ImageFileFormat.Png, image_filename, grabResult);
//image_algorithms();
Image image = Image.FromFile(image_filename);
var ms = new MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
var bytes = ms.ToArray();
var imageMemoryStream = new MemoryStream(bytes);
Image imgFromStream = Image.FromStream(imageMemoryStream);
pictureBox1.Image = imgFromStream;
pictureBox1.Refresh();
}
else
{
Console.WriteLine("Error: {0} {1}", grabResult.ErrorCode,
grabResult.ErrorDescription);
}
}
}