Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewFrameEventHandler is not firing #56

Open
aalthafari opened this issue Jun 26, 2022 · 1 comment
Open

NewFrameEventHandler is not firing #56

aalthafari opened this issue Jun 26, 2022 · 1 comment

Comments

@aalthafari
Copy link

aalthafari commented Jun 26, 2022

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 ?

@aalthafari
Copy link
Author

@andrewkirillov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant