示例#1
0
 public void Dispose()
 {
     if (BackBrush != null)
     {
         BackBrush.Dispose();
     }
     if (FontBrush != null)
     {
         FontBrush.Dispose();
     }
     if (Icon != null)
     {
         Icon.Dispose();
     }
 }
示例#2
0
文件: Camera.cs 项目: zmaples/iSpy
        private void VideoNewFrame(object sender, NewFrameEventArgs e)
        {
            var nf = NewFrame;
            var f  = e.Frame;

            if (_requestedToStop || nf == null || f == null)
            {
                return;
            }


            if (_lastframeEvent > DateTime.MinValue)
            {
                if ((Helper.Now < _nextFrameTarget))
                {
                    return;
                }
                CalculateFramerates();
            }

            _lastframeEvent = Helper.Now;

            if (_updateResources)
            {
                _updateResources = false;
                DrawFont.Dispose();
                DrawFont = null;
                ForeBrush.Dispose();
                ForeBrush = null;
                BackBrush.Dispose();
                BackBrush = null;
                SetMaskImage();
                RotateFlipType rft;
                if (Enum.TryParse(CW.Camobject.rotateMode, out rft))
                {
                    RotateFlipType = rft;
                }
                else
                {
                    RotateFlipType = RotateFlipType.RotateNoneFlipNone;
                }
            }


            Bitmap bmOrig  = null;
            bool   bMotion = false;

            lock (_sync)
            {
                try
                {
                    bmOrig = ResizeBmOrig(f);

                    if (RotateFlipType != RotateFlipType.RotateNoneFlipNone)
                    {
                        bmOrig.RotateFlip(RotateFlipType);
                    }

                    _width  = bmOrig.Width;
                    _height = bmOrig.Height;

                    if (ZPoint == Point.Empty)
                    {
                        ZPoint = new Point(bmOrig.Width / 2, bmOrig.Height / 2);
                    }

                    if (CW.NeedMotionZones)
                    {
                        CW.NeedMotionZones = !SetMotionZones(CW.Camobject.detector.motionzones);
                    }

                    if (Mask != null)
                    {
                        ApplyMask(bmOrig);
                    }

                    if (CW.Camobject.alerts.active && Plugin != null && Alarm != null)
                    {
                        bmOrig = RunPlugin(bmOrig);
                    }

                    var bmd = bmOrig.LockBits(new Rectangle(0, 0, bmOrig.Width, bmOrig.Height), ImageLockMode.ReadWrite, bmOrig.PixelFormat);

                    //this converts the image into a windows displayable image so do it regardless
                    using (var lfu = new UnmanagedImage(bmd))
                    {
                        if (_motionDetector != null)
                        {
                            bMotion = ApplyMotionDetector(lfu);
                        }
                        else
                        {
                            MotionDetected = false;
                        }

                        if (CW.Camobject.settings.FishEyeCorrect)
                        {
                            _feCorrect.Correct(lfu, CW.Camobject.settings.FishEyeFocalLengthPX,
                                               CW.Camobject.settings.FishEyeLimit, CW.Camobject.settings.FishEyeScale, ZPoint.X,
                                               ZPoint.Y);
                        }

                        if (ZFactor > 1)
                        {
                            var f1 = new ResizeNearestNeighbor(lfu.Width, lfu.Height);
                            var f2 = new Crop(ViewRectangle);
                            try
                            {
                                using (var imgTemp = f2.Apply(lfu))
                                {
                                    f1.Apply(imgTemp, lfu);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorHandler?.Invoke(ex.Message);
                            }
                        }
                    }
                    bmOrig.UnlockBits(bmd);
                    PiP(bmOrig);
                    AddTimestamp(bmOrig);
                }
                catch (UnsupportedImageFormatException ex)
                {
                    CW.VideoSourceErrorState   = true;
                    CW.VideoSourceErrorMessage = ex.Message;

                    bmOrig?.Dispose();

                    return;
                }
                catch (Exception ex)
                {
                    bmOrig?.Dispose();

                    ErrorHandler?.Invoke(ex.Message);

                    return;
                }


                if (MotionDetector != null && !CW.Calibrating && MotionDetector.MotionProcessingAlgorithm is BlobCountingObjectsProcessing && !CW.PTZNavigate && CW.Camobject.settings.ptzautotrack)
                {
                    try
                    {
                        ProcessAutoTracking();
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler?.Invoke(ex.Message);
                    }
                }
            }

            if (!_requestedToStop)
            {
                nf.Invoke(this, new NewFrameEventArgs(bmOrig));
            }
            if (bMotion)
            {
                TriggerDetect(this);
            }
        }