public void Init(Setting camera = null) { MainForm form = (MainForm)this.Owner; Setting cam; if (camera == null) { cam = form.camera; } else { cam = camera; } double downRatio = ((double)Configure_croparea.Width / (double)form.panel1.Width); Configure_textbox_camID.Text = Convert.ToString(cam.camID, 10); Configure_textbox_rtspurl.Text = cam.camURL; Configure_textbox_savepath.Text = cam.savePath; _cropRect = new Rectangle((int)(cam.cropX * downRatio), (int)(cam.cropY * downRatio), (int)(cam.cropWidth * downRatio), (int)(cam.cropHeight * downRatio)); Configure_croparea.Invalidate(); Configure_UpDown_CropX.Value = _cropRect.X; Configure_UpDown_CropY.Value = _cropRect.Y; Configure_UpDown_CropWidth.Value = _cropRect.Width; Configure_UpDown_CropHeight.Value = _cropRect.Height; Configure_textbox_timeout.Text = Convert.ToString(cam.timeout, 10); Configure_textbox_countForPass.Text = Convert.ToString(cam.countForPass, 10); Configure_checkBox_isResize.Checked = cam.isResize; Configure_textbox_size.Text = Convert.ToString(cam.size, 10); }
public void LoadConfigFile(string path) { try { System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer); Setting camera = new Setting(); XmlSerializer formatter = new XmlSerializer(camera.GetType()); camera = (Setting)formatter.Deserialize(stream); // read values _camID = camera.camID; _camURL = camera.camURL; _cropX = camera.cropX; _cropY = camera.cropY; _cropWidth = camera.cropWidth; _cropHeight = camera.cropHeight; _savePath = camera.savePath; _isResize = camera.isResize; _timeout = camera.timeout; _countForPass = camera.countForPass; _size = camera.size; stream.Close(); fs.Close(); } catch (Exception ex) { Console.WriteLine("Config File read error"); } }
private void Configure_button_load_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "설정 파일|*.cfg"; dialog.Title = "설정 파일 열기"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.FileStream fs = (System.IO.FileStream)dialog.OpenFile(); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, (int)fs.Length); System.IO.MemoryStream stream = new System.IO.MemoryStream(buffer); Setting camera = new Setting(); XmlSerializer formatter = new XmlSerializer(camera.GetType()); camera = (Setting)formatter.Deserialize(stream); Init(camera); stream.Close(); fs.Close(); } }
private void Configure_button_save_Click(object sender, EventArgs e) { SaveFileDialog dialog = new SaveFileDialog(); MainForm form = (MainForm)this.Owner; dialog.Filter = "설정 파일|*.cfg"; dialog.Title = "설정 파일 저장"; dialog.ShowDialog(); if (dialog.FileName != "") { Setting camera = new Setting(); double upRatio = ((double)form.panel1.Width / (double)Configure_croparea.Width); camera.camID = Convert.ToInt32(Configure_textbox_camID.Text, 10); camera.camURL = Configure_textbox_rtspurl.Text; camera.savePath = Configure_textbox_savepath.Text; camera.cropX = (int)(_cropRect.X * upRatio); camera.cropY = (int)(_cropRect.Y * upRatio); camera.cropWidth = (int)(_cropRect.Width * upRatio); camera.cropHeight = (int)(_cropRect.Height * upRatio); camera.timeout = Convert.ToInt32(Configure_textbox_timeout.Text); camera.countForPass = Convert.ToInt32(Configure_textbox_countForPass.Text); camera.isResize = Configure_checkBox_isResize.Checked; camera.size = Convert.ToInt32(Configure_textbox_size.Text); System.IO.FileStream fs = (System.IO.FileStream)dialog.OpenFile(); XmlSerializer formatter = new XmlSerializer(camera.GetType()); formatter.Serialize(fs, camera); fs.Close(); } }
private void InitCamera() { camera = new Setting(); camera.PropertyChanged += camera_PropertyChanged; if (configPath.Length > 0) { camera.LoadConfigFile(configPath); } }