Exemple #1
0
        private Image scaleImageToFitFormat(PageSize pageSize, Image img)
        {
            float hScale = img.HorizontalResolution * 10.1f;
            float vScale = img.VerticalResolution * 6.7f;

            switch (pageSize)
            {
            case PageSize.A0:
                hScale = Convert.ToSingle(hScale * Math.Pow(1.45f, 4)) / (img.Width / img.HorizontalResolution);
                vScale = Convert.ToSingle(vScale * Math.Pow(1.35f, 4)) / (img.Height / img.VerticalResolution);
                break;

            case PageSize.A1:
                hScale = Convert.ToSingle(hScale * Math.Pow(1.45f, 3)) / (img.Width / img.HorizontalResolution);
                vScale = Convert.ToSingle(vScale * Math.Pow(1.35f, 3)) / (img.Height / img.VerticalResolution);
                break;

            case PageSize.A2:
                hScale = Convert.ToSingle(hScale * Math.Pow(1.45f, 2)) / (img.Width / img.HorizontalResolution);
                vScale = Convert.ToSingle(vScale * Math.Pow(1.35f, 2)) / (img.Height / img.VerticalResolution);
                break;

            case PageSize.A3:
                hScale = (hScale * 1.5f) / (img.Width / img.HorizontalResolution);
                vScale = (vScale * 1.4f) / (img.Height / img.VerticalResolution);
                break;

            default:
                hScale = hScale / (img.Width / img.HorizontalResolution);
                vScale = vScale / (img.Height / img.VerticalResolution);
                break;
            }



            if (hScale > vScale)
            {
                return(MapWithQRCodeWriter.ScaleByPercent(img, hScale));
            }
            else
            {
                return(MapWithQRCodeWriter.ScaleByPercent(img, vScale));
            }
        }
        public MainForm()
        {
            InitializeComponent();

            this.FormClosing += new FormClosingEventHandler(mainForm_FormClosing);
            this.Move += delegate { new UpdateMapSizeAndPosition(this.mainVideo, MapOverlayForm.Instance).execute(); };
            this.SizeChanged += delegate { new UpdateMapSizeAndPosition(this.mainVideo, MapOverlayForm.Instance).execute(); };
            this.Load += delegate { new UpdateMapSizeAndPosition(this.mainVideo, MapOverlayForm.Instance).execute(); };

            MapOverlayForm.Instance.Owner = this;
            MapOverlayForm.Instance.Show();

            this.setDetector(Settings.Default.SelectedDetectorIndex);
            this.detectorComboBox.SelectedIndex = Settings.Default.SelectedDetectorIndex;
            this.detectorComboBox.SelectedValueChanged += delegate { this.setDetector(this.detectorComboBox.SelectedIndex); };

            this.updateVideoSourceCombo();
            this.videoSourceCombo.SelectedValueChanged += delegate { new UpdateVideoFormatComboCommand(this.videoSourceCombo.SelectedIndex, this.videoFormatCombo).execute(); };
            try
            {
                this.videoSourceCombo.SelectedIndex = Settings.Default.VideoSourceIndex;
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            Command changeVideoFormatCommand = new ChangeVideoFormatCommand(this.mainVideo, this.videoSourceCombo, this.videoFormatCombo, this);
            this.videoFormatCombo.SelectedValueChanged += delegate { changeVideoFormatCommand.execute(); };
            try
            {
                this.videoFormatCombo.SelectedIndex = Settings.Default.VideoFormatIndex;
                changeVideoFormatCommand.execute();
            }
            catch (ArgumentOutOfRangeException)
            {
            }
            this.brightness.Scroll += delegate { this.videoPreprocessor.Brightness = this.brightness.Value; };

            this.contrast.Scroll += delegate { this.videoPreprocessor.Contrast = this.contrast.Value; };

            this.saturation.Scroll += delegate { this.videoPreprocessor.Saturation = Convert.ToSingle(this.saturation.Value) / 100.0f; };

            this.checkServerState.CheckedChanged += delegate { if (this.checkServerState.Checked) { NetworkServer.Instance.Start(); } else { NetworkServer.Instance.Stop(); } };
            NetworkServer.Instance.serverLog = this.serverLog;
            if (Settings.Default.NetworkServerActive)
                NetworkServer.Instance.Start();

            this.checkBroadcast.CheckedChanged += delegate { if (this.checkBroadcast.Checked) { Broadcaster.Instance.Start(); } else { Broadcaster.Instance.Stop(); } };
            if (Settings.Default.BroadcastLocationSources)
                Broadcaster.Instance.Start();

            this.mapZoom.Scroll += delegate { new MapZoomCommand(this.mapZoom.Value, false).execute(); };
            this.mapOpacity.Scroll += delegate { MapOverlayForm.Instance.Opacity = Convert.ToDouble(this.mapOpacity.Value) / 100.0; };
            this.mapBearing.Scroll += delegate { MapOverlayForm.Instance.RotationAngle = Convert.ToSingle(this.mapBearing.Value); };

            this.showDetectorSettings.Click += delegate { this.detector.SettingsForm().Show(); };

            this.addUser.Click += delegate { new CreateLocationSourceCommand(this.userListContainer, this.detectorFactory).execute(); };

            this.checkRecordUsersTracks.CheckedChanged += delegate {
                if (this.checkRecordUsersTracks.Checked)
                {
                    RecorderManager.Instance.pauseRecording();
                }
                else
                {
                    RecorderManager.Instance.continueRecording();
                };
            };

            this.paperFormat.SelectedIndex = Settings.Default.QRCodePaperFormat;
            this.saveQR.Click += delegate
            {
                MapWithQRCodeWriter writer = new MapWithQRCodeWriter();
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                saveFileDialog.Filter = "pdf files (*.pdf)|*.pdf";
                saveFileDialog.FilterIndex = 1;
                saveFileDialog.RestoreDirectory = true;
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    writer.write(this.paperFormat.SelectedIndex, saveFileDialog.FileName);
                }
                saveFileDialog.Dispose();
            };

            qrCodeEncoder = new MapWithQRCodeReader();
            this.encodeQR.Click += delegate
            {
                this.qrCodeEncoder.decode(this.mainVideo.GetCurrentVideoFrame());
            };
        }