Exemple #1
0
        public void Deserialize(string filename)
        {
            if (!File.Exists(filename))
            {
                btnResetSessionMem.Visible = false;
                return;
            }

            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      fs        = File.Open(filename, FileMode.Open);

            try
            {
                object obj = formatter.Deserialize(fs);
                CameraLayout = (CameraLayout)obj;
                fs.Flush();
                fs.Close();
                fs.Dispose();
            }
            catch (Exception)
            {
                fs.Flush();
                fs.Close();
                fs.Dispose();
                File.Delete(MemoryPath);
                return;
            }

            // Start Video
            foreach (FilterInfo device in VideoDevices)
            {
                if (device.MonikerString == CameraLayout.CamID)
                {
                    StartStream(CameraLayout.CamID);
                }
            }
            System.Threading.Thread.SpinWait(1000);
            if (!VideoSource.IsRunning)
            {
                return;
            }

            // Restore Position
            StartPosition   = FormStartPosition.Manual;
            Size            = CameraLayout.WindowSize;
            DesktopLocation = CameraLayout.WindowLocation;

            // Restore Options
            Rotation = CameraLayout.Rotation;
            Color    = CameraLayout.CrosshairColor;
            if (!CameraLayout.ShowListView)
            {
                btnToggleListView.PerformClick();
            }
            if (CameraLayout.ShowCrosshair)
            {
                btnToggleCrosshair.PerformClick();
            }
        }
Exemple #2
0
        public CameraViewer()
        {
            InitializeComponent();
            Controls.AddRange(new Control[] { PictureBox, Splitter, ListBox });
            ListBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
            VideoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            ListBox.Items.AddRange(VideoDevices.Select(x => x.Name).ToArray());
            ResizeEnd       += CameraViewer_WindowChanged;
            LocationChanged += CameraViewer_WindowChanged;

            CameraLayout = new CameraLayout();
            Deserialize(MemoryPath);
        }
Exemple #3
0
        public void Serialize(CameraLayout cameraLayout, string filename)
        {
            FileInfo fileInfo = new FileInfo(filename);

            if (!fileInfo.Directory.Exists)
            {
                return;
            }

            Stream          ms        = File.OpenWrite(filename);
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(ms, cameraLayout);
            ms.Flush();
            ms.Close();
            ms.Dispose();
        }