0

I receive 30 raw images per second via USB. (real time camera iamge / but not webcam)

// raw image is Format32bppPArgb Bitmap

while ( true ) // Recevie Image loop Using Task
{
    ...
    picturebox1.Image = raw_image;
    // panel1.BackgroundImage = raw_image; // or using panel to display
    ...
}

I updated the image to make it look like an Video. When the image is 15fps, it's the program working properly. But 30fps, GUI is broken. The image area is refreshed smoothly and well. However, other components will not be updated if there is a change, causing problems. (such as radiobutton, panel, title bar, etc..) This seems to occur noticeably when the area of drawing the image is widened.

As a result of referring to other articles in stackoverflow, I was able to check some related information, but I couldn't solve it clearly using Winform. it seems that fast redrawing in this way is difficult through winform. (I don't know if I got it right.)

Are there any good ways or keywords to solve this problem? Thank you for reading it.

이서연
  • 1
  • 2

2 Answers2

0

I had a similar problem. It helped me when I called the Refresh() and Update() functions at any change on the surrounding controls.

// Label is only example, you can user any control you like
private void ChangeLabel()
{
    label1.text = "new text";
    label1.Refresh();
    label1.Update();
}

Maybe it would be enough to add only one of the functions.

cooper538
  • 1
  • 1
  • You do know that `Control.Refresh()` is actually `Control.Invalidate();` + `Control.Update();`. So now you're doing: `Control.Invalidate(); Control.Update(); Control.Update();`. I'd mention the blocking `while (true)` loop (in WinForms) and ask how the *frame-rate* is generated and calculated, how the Images are transferred, what is responsible for this operation etc. – Jimi Sep 09 '20 at 18:45
  • @Jimi Thank you for your reply and interest. / in main thread Create and start Task(USB receive & Parsing(make image) Thread)., `tListen = new Task(...); tListen.Start(); / tParsing = new Task(...); tParsing.Start();` The 'while (true)' loop in the text is the structure of parsing thread and actually breaks when the usb is disconnected.The frame speed is consistently sent from a device connected via USB.When the data comes in, create an image and update the picturebox.The image is 400x400(Bayer->RGB). This is an endoscopic viewer that requires real-time control. – 이서연 Sep 10 '20 at 01:30
  • You have to show your code, to provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) (which is very important to determine the context of the operations). -- A Task is run in the ThreadPool Thread: the very small piece of code you posted cannot work as it is, since you cannot access a UI Element from a Thread other than the UI Thread directly (`picturebox1.Image = raw_image;`), you'd get a `InvalidOperationException` because you're attempting an invalid Cross-Thread access to GUI objects. – Jimi Sep 10 '20 at 08:11
  • @Jimi The problem was resolved through another attempt ! . The default bitmap resizing was thought to be heavy. 'zoom mode' has been changed to 'none'. The image was resized to fit the panel size before making it into a bitmap. The image was created and call invalidate(). Displayed through "Graphics.DrawImage". in the panel's "onpaint event". Now everything is working normally. Thank you for your kind attention. – 이서연 Sep 11 '20 at 03:52
0

The default bitmap resizing was thought to be heavy. 'zoom mode' has been changed to 'none'. The image was resized to fit the panel size before making it into a bitmap. (this case, i use opencvsharp resize / image.ToBitmap() )

The image was created and call invalidate(). Displayed through "Graphics.DrawImage" in the panel's "onpaint event". Now everything is working normally.

이서연
  • 1
  • 2