Exemple #1
0
        private void Connect2()
        {
            // Second part of Connect function.
            // The function is split because the first part might need to be run repeatedly and from non UI thread,
            // while this part must run on the UI thread.

            metadata.ImageSize = new Size(imageDescriptor.Width, imageDescriptor.Height);
            metadata.PostSetupCapture();

            AllocateDelayer();

            // Start recorder thread.
            // It will be dormant until recording is started but it has the same lifetime as the pipeline.
            consumerRecord = new ConsumerMJPEGRecorder();
            recorderThread = new Thread(consumerRecord.Run)
            {
                IsBackground = true
            };
            recorderThread.Name = consumerRecord.GetType().Name;
            recorderThread.Start();

            // Make sure the viewport will not use the bitmap allocated by the consumerDisplay as it is about to be disposed.
            viewportController.ForgetBitmap();
            viewportController.InitializeDisplayRectangle(cameraSummary.DisplayRectangle, new Size(imageDescriptor.Width, imageDescriptor.Height));

            // Initialize pipeline.
            pipelineManager.Connect(imageDescriptor, (IFrameProducer)cameraGrabber, consumerDisplay, consumerRecord);

            nonGrabbingInteractionTimer.Enabled = false;

            if (!PreferencesManager.CapturePreferences.UseCameraSignalSynchronization)
            {
                double framerate = PreferencesManager.CapturePreferences.DisplaySynchronizationFramerate;
                if (framerate == 0)
                {
                    framerate = 25;
                }

                grabTimer.Interval = (int)(1000.0 / framerate);
                grabTimer.Enabled  = true;
            }

            cameraGrabber.GrabbingStatusChanged += Grabber_GrabbingStatusChanged;
            cameraGrabber.Start();

            UpdateTitle();
            cameraConnected = true;
        }
        private void InitializeDisplayRectangle(Size imgSize, long timestamp)
        {
            int scale = 2;

            // center around current point with zoom.
            PointF position                  = track.GetPosition(timestamp);
            PointF normalizedPosition        = new PointF(position.X / imgSize.Width, position.Y / imgSize.Height);
            SizeF  normalizedHostSize        = new SizeF((float)pnlViewport.Width / imgSize.Width, (float)pnlViewport.Height / imgSize.Height);
            PointF normalizedHostCenter      = new PointF(normalizedHostSize.Width / 2, normalizedHostSize.Height / 2);
            PointF normalizedDisplayLocation = new PointF(normalizedHostCenter.X - (normalizedPosition.X * scale), normalizedHostCenter.Y - (normalizedPosition.Y * scale));

            PointF topLeft  = new PointF(normalizedDisplayLocation.X * imgSize.Width, normalizedDisplayLocation.Y * imgSize.Height);
            Size   fullSize = new Size(imgSize.Width * scale, imgSize.Height * scale);

            Rectangle display = new Rectangle((int)topLeft.X, (int)topLeft.Y, fullSize.Width, fullSize.Height);

            viewportController.InitializeDisplayRectangle(display, imgSize);
        }