Beispiel #1
0
        // Paint control
        protected override void OnPaint(PaintEventArgs pe)
        {
            if ((needSizeUpdate) || (firstFrame))
            {
                UpdatePosition( );
                needSizeUpdate = false;
            }

            // lock
            Monitor.Enter(this);

            Graphics  g   = pe.Graphics;
            Rectangle rc  = this.ClientRectangle;
            Pen       pen = new Pen(rectColor, 1);

            // draw rectangle
            g.DrawRectangle(pen, rc.X, rc.Y, rc.Width - 1, rc.Height - 1);

            if (camera != null)
            {
                try
                {
                    camera.Lock( );

                    // draw frame
                    if (camera.LastFrame != null)
                    {
                        g.DrawImage(camera.LastFrame, rc.X + 1, rc.Y + 1, rc.Width - 2, rc.Height - 2);
                        firstFrame = false;
                    }
                    else
                    {
                        // Create font and brush
                        Font       drawFont  = new Font("Arial", 12);
                        SolidBrush drawBrush = new SolidBrush(Color.White);

                        g.DrawString("Connecting ...", drawFont, drawBrush, new PointF(5, 5));

                        drawBrush.Dispose( );
                        drawFont.Dispose( );
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    camera.Unlock( );
                }
            }

            pen.Dispose( );

            // unlock
            Monitor.Exit(this);

            base.OnPaint(pe);
        }
        // Update motion detector
        private void SetMotionDetector()
        {
            Camera camera = cameraWindow.Camera;

            if (camera != null)
            {
                camera.Lock();
                camera.MotionDetector = detector;

                // reset statistics
                statIndex = statReady = 0;
                camera.Unlock();
            }
        }
        // Update motion detector
        private void SetMotionDetector( )
        {
            Camera camera = cameraWindow.Camera;

            // enable/disable motion alarm
            if (detector != null)
            {
                detector.MotionLevelCalculation = motionAlarmItem.Checked;
            }

            // set motion detector to camera
            if (camera != null)
            {
                camera.Lock( );
                camera.MotionDetector = detector;

                // reset statistics
                statIndex = statReady = 0;
                camera.Unlock( );
            }
        }
        // On new frame
        private void Camera_NewFrame(object sender, System.EventArgs e)
        {
            if ((intervalsToSave != 0) && (saveOnMotion == true))
            {
                // lets save the frame
                if (writer == null)
                {
                    // create file name
                    DateTime date     = DateTime.Now;
                    String   fileName = String.Format("{0}-{1}-{2} {3}-{4}-{5}.avi",
                                                      date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second);

                    try
                    {
                        // create AVI writer
                        writer = new AVIWriter("wmv3");
                        // open AVI file
                        writer.Open(fileName, cameraWindow.Camera.Width, cameraWindow.Camera.Height);
                    }
                    catch (ApplicationException)
                    {
                        if (writer != null)
                        {
                            writer.Dispose( );
                            writer = null;
                        }
                    }
                }

                // save the frame
                Camera camera = cameraWindow.Camera;

                camera.Lock( );
                writer.AddFrame(camera.LastFrame);
                camera.Unlock( );
            }
        }