Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a C# form app to view webcam using AForge. The preview of webcam is taken to pciturebox. I have taken picturebox so that I can resize the preview window and image is stretched. Problem is that the preview is freezed after few seconds like 15-20 approx everytime after I start app. I can take VideoSourcePlayer control, but it only resizes respective of camera resolution. Suppose if camera resolution is 1280x720 the VideoSourcePlayer will resize to 1280x720 and no other sizes even though I need to view in full screen.

Please suggest solution for either picturebox preview don't freeze or resizing of VideoSourcePlayer irrespective of camera resolution.

Thanks & Regards.

This question has the same issue:
Vb.net aforge video capture - memory is consumed and the camera freezes[^]

What I have tried:

I have tried lower framerate. Also tried EnableFrameServerMode in registry as suggested here: https://www.winhelponline.com/blog/webcam-anniversary-update-windows-10-yuys-standard/[^]

Code:
VideoCaptureDeviceForm form = new VideoCaptureDeviceForm();
videoSource.NewFrame += new NewFrameEventHandler(videoSource_NewFrame);
videoSource.Start();>

And in event handle
Bitmap video = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = video;
Posted
Updated 12-Aug-21 14:58pm
Comments
[no name] 11-Aug-21 12:49pm    
If you were using WPF or UWP, you could use a ViewBox to scale.

1 solution

Images need to be disposed of when no longer in use, so try replacing
C#
pictureBox1.Image = video;

by
C#
Image prevImage=pictureBox1.Image;
pictureBox1.Image = video;
if (prevImage!=null) prevImage.Dispose();

:)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900