private void WorkThreadFunction(object webcamImage)
 {
     try
     {
         WebcamImage lastImageObj = new WebcamImage();
         lastImageObj = webcamImage as WebcamImage;
         //lastImageObj = (WebcamImage)webcamImage.Clone();
         //System.Drawing.Bitmap lastBitmap = (System.Drawing.Bitmap)lastImageObj.image.Clone();
         //DateTime lastTimestamp = lastImageObj.timestamp;
         //int frameCount = lastImageObj.frameCount;
         // TODO DEBUG crossThreadAccess violation or something else... the object is in use...
         saveImage(lastImageObj.image, lastImageObj.timestamp);
         lastImageObj.Dispose();
         imageToDisk.Dispose();
         imageToGUI.Dispose();
         webcamImage = null;
     }
     catch (ApplicationException appEx)
     {
         ConsoleBuddy.WriteException(appEx, "WorkThreadFunction");
     }
     catch (InvalidOperationException invOpEx)
     {
         ConsoleBuddy.WriteException(invOpEx, "WorkThreadFunction");
     }
     catch (Exception e)
     {
         ConsoleBuddy.WriteException(e, "WorkThreadFunction");
     }
 }
Beispiel #2
0
        public WebcamImage Clone()
        {
            WebcamImage clone = new WebcamImage();

            clone.image = (System.Drawing.Bitmap) this.image.Clone();
            DateTime time = new DateTime();

            time            = this.timestamp;
            clone.timestamp = time;
            int frmCount = 0;

            frmCount         = this.frameCount;
            clone.frameCount = frmCount;
            return(clone);
        }
        void videoDeviceForCapture_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            try
            {
                int videoDeviceFramesReceived = this.videoDeviceForCapture.FramesReceived;
                if (videoDeviceFramesReceived <= 1)
                {
                    ConsoleBuddy.WriteLineGreen("Number of frames received from last NewFrame event: " + videoDeviceFramesReceived.ToString());
                }
                else
                {
                    ConsoleBuddy.WriteLineRed("Number of frames received from last NewFrame event: " + videoDeviceFramesReceived.ToString());
                }
                this.frameCount = ++this.frameCount;
                DateTime now = DateTime.Now;
                //messages += "Event in WebcamLibrary @ " + now.ToString() + "::" + now.Millisecond.ToString() + ";\t frames received:" + this.frameCount.ToString() + "\r\n";
                System.Drawing.Bitmap copy = (System.Drawing.Bitmap)eventArgs.Frame.Clone();

                /*          this.lastImage = new WebcamImage();
                 *        this.lastImage.image = new Bitmap(copy);
                 *        this.lastImage.timestamp = now;*/
                WebcamImage lastImageObj = new WebcamImage();
                lastImageObj.image      = new Bitmap(copy);
                lastImageObj.timestamp  = now;
                lastImageObj.frameCount = this.frameCount;
                //saveImage(copy, now);
                // 21/11/2016 commented ThreadPool call
                //ThreadPool.QueueUserWorkItem(new WaitCallback(WorkThreadFunction), lastImageObj);
                //
                //this.thread = new Thread(new ThreadStart(WorkThreadFunction));
                //thread.Start();

                NewFrameImageEventArgs e = new NewFrameImageEventArgs(lastImageObj);
                OnNewFrameImage(e);
                copy.Dispose();
            }
            catch (System.NullReferenceException NullEx)
            {
                System.Console.WriteLine("System.NullReferenceException; Message: " + NullEx.Message + "; Source: " + NullEx.Source + "; TargetSite: " + NullEx.TargetSite + ";InnerException: " + NullEx.InnerException + "; Data: " + NullEx.Data + "; HelpLink: " + NullEx.HelpLink + "; StackTrace: " + NullEx.StackTrace);
            }
        }