i m writing a program using C# with sentisight sdk for detecting the camera and capturing the image from the webcam. Now i can only capture the still image in the picturebox. I want to make a stream of image(like a video) before i stop the capturing. so i need to grab frames on each Tick event and pass it to picturebox.

But i m a beginner in C# so any one can guide me how to solve it.... thank u

Dani AI

Generated

As pointed out, polling with a timer is one way to get a stream of frames. Two safer, beginner-friendly patterns are shown below: 1) use the camera/SDK frame callback (preferred if the sentisight sdk exposes one), or 2) poll the SDK from a background loop and marshal each frame to the UI. Key points: never do heavy work on the UI thread, always marshal UI updates with Invoke/BeginInvoke, and dispose old Bitmaps to avoid memory leaks.

Example: safe UI updater (clones the incoming Bitmap and disposes the original)

private void DisplayFrame(Bitmap frame)
{
    if (pictureBox.InvokeRequired)
    {
        pictureBox.BeginInvoke(new Action<Bitmap>(DisplayFrame), frame);
        return;
    }

    var old = pictureBox.Image;
    pictureBox.Image = (Bitmap)frame.Clone(); // clone in case SDK reuses the original
    old?.Dispose();
    frame.Dispose();
}

Example: background polling loop (replace GrabFrameFromSdk with your sentisight call)

private CancellationTokenSource _cts;

private void StartCapture()
{
    _cts = new CancellationTokenSource();
    Task.Run(async () =>
    {
        while (!_cts.Token.IsCancellationRequested)
        {
            var frame = GrabFrameFromSdk(); // returns Bitmap or null
            if (frame != null)
                DisplayFrame(frame); // DisplayFrame takes care of cloning/disposing
            await Task.Delay(33); // ~30 FPS; tune as needed
        }
    }, _cts.Token);
}

private void StopCapture()
{
    _cts?.Cancel();
}

Troubleshooting tips: System.Windows.Forms.Timer runs on the UI thread and can stutter if processing is slow—use a Task loop or System.Timers.Timer. If the sentisight sdk provides a NewFrame/FrameReady event, subscribe to that instead of polling. If you see OutOfMemory or increasing RAM, ensure every replaced PictureBox.Image is disposed. For CPU-heavy processing, do it off the UI thread and only send a small display copy to the PictureBox.

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.