Skip to content

NewFrameEventHandler is not firing #56

@aalthafari

Description

@aalthafari

I have an ASP.NET code that is using WinFroms, I am trying to capture images from the webcam.

I created a camera handler class as follows:

public static Bitmap img;
        public static void Initation()
        {
            VideoCaptureDevice video;
            FilterInfoCollection filter;
            try
            {
                filter = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                video = new VideoCaptureDevice(filter[0].MonikerString);
                video.NewFrame += new NewFrameEventHandler(Camera_On);
                video.Start();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    private static void Camera_On(object sender, NewFrameEventArgs eventArgs)
    {
        img = (Bitmap)eventArgs.Frame.Clone();
    }
    public static string Save()
    {
        System.Drawing.Imaging.ImageFormat format = null;
        format = System.Drawing.Imaging.ImageFormat.Jpeg;
        string name = InitialSetup.currentLkr.Name + @"\" + InitialSetup.currentLkr.Name + "_" + DateTime.Now.ToString() + ".jpg";
        name = name.Replace(@"/", "_");
        name = name.Replace(" ", "_");
        name = name.Replace(":", "-");
        name = @"D:\" + name;
        img.Save(name);
        return name;
    }

I first call Initiate and then I call Save, the code was working fine, then suddenly the even handler stopped firing and I started to get null value in my img variable.

Any ideas on what might be the cause to that ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions