pictureBox在C#GUI中更新缓慢?
我用机器视觉照相机拍摄图像,并将其存储到文件夹中。我想在存储下一幅图像之前,将保存的图像显示在pictureBox中。我的代码成功地在pictureBox中显示了图像,但是有一个延迟,即当图像10保存到文件夹时,GUI仅显示图像3。我不知道如何提高性能,以允许GUI在拍摄图像时实时更新 我认为我的问题可能是因为使用png图像创建MemoryStream而不是byte[]缓冲区(原始传感器数据)。我尝试使用字节[],但未能成功填充pictureBox 这是我的代码:pictureBox在C#GUI中更新缓慢?,c#,user-interface,camera,refresh,picturebox,C#,User Interface,Camera,Refresh,Picturebox,我用机器视觉照相机拍摄图像,并将其存储到文件夹中。我想在存储下一幅图像之前,将保存的图像显示在pictureBox中。我的代码成功地在pictureBox中显示了图像,但是有一个延迟,即当图像10保存到文件夹时,GUI仅显示图像3。我不知道如何提高性能,以允许GUI在拍摄图像时实时更新 我认为我的问题可能是因为使用png图像创建MemoryStream而不是byte[]缓冲区(原始传感器数据)。我尝试使用字节[],但未能成功填充pictureBox 这是我的代码: // Grab a numbe
// 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);
}
}
}
//获取大量图像。
对于(int i=0;i
5000毫秒是5秒,比显示图像所需的时间长得多。时间到底到哪里去了???@TaW 5000是一个超时计数器,用于指示图像是否掉帧(几乎从不)。这是相机制造商SDK的一部分。好的,那么你的数字是多少?需要的速度和图像大小“?~1图像每秒保存并显示在GUI上,我在for循环的末尾添加了System.Threading.Thread.Sleep(1000)以降低速度,但仍然延迟。图像大小:3840x2748um,那么问题是:太慢还是太快???另外:您需要显示全尺寸吗?