void Record() { int FrameRate = (int)FpsUpDown.Value; Size RSize = RecordPanel.Size; int RndNum = new Random().Next(); string OutFile = Path.GetFullPath(string.Format("rec_{0}.avi", RndNum)); string OutFileCompressed = Path.GetFullPath(string.Format("rec_{0}.webm", RndNum)); AviWriter Writer = new AviWriter(OutFile); Writer.FramesPerSecond = FrameRate; Writer.EmitIndex1 = true; IAviVideoStream VStream = Writer.AddVideoStream(RSize.Width, RSize.Height, BitsPerPixel.Bpp24); VStream.Codec = KnownFourCCs.Codecs.Uncompressed; VStream.BitsPerPixel = BitsPerPixel.Bpp24; Bitmap Bmp = new Bitmap(RSize.Width, RSize.Height); Graphics G = Graphics.FromImage(Bmp); Stopwatch SWatch = new Stopwatch(); SWatch.Start(); while (!AbortRecording) { G.CopyFromScreen(DesktopLocation.Add(RecorderOffset), Point.Empty, RSize); //G.DrawString("Text Embedding", SystemFonts.CaptionFont, Brushes.Red, new PointF(0, 0)); Bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); byte[] Data = Bmp.ToByteArray(); VStream.WriteFrame(true, Data, 0, Data.Length); while ((float)SWatch.ElapsedMilliseconds / 1000 < 1.0f / FrameRate) { ; } SWatch.Restart(); } G.Dispose(); Writer.Close(); if (WebmCheckBox.Checked) { Program.FFMPEG("-i \"{0}\" -c:v libvpx -b:v 1M -c:a libvorbis \"{1}\"", OutFile, OutFileCompressed); File.Delete(OutFile); } }
bool ReadSettings() { RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software"); RegistryKey wroxKey = softwareKey.OpenSubKey("WroxPress"); if (wroxKey == null) { return(false); } RegistryKey selfPlacingWindowKey = wroxKey.OpenSubKey("SelfPlacingWindow"); if (selfPlacingWindowKey == null) { return(false); } else { listBoxMessages.Items.Add("Successfully opened key " + selfPlacingWindowKey.ToString()); } int redComponent = (int)selfPlacingWindowKey.GetValue("Red"); int greenComponent = (int)selfPlacingWindowKey.GetValue("Green"); int blueComponent = (int)selfPlacingWindowKey.GetValue("Blue"); this.BackColor = Color.FromArgb(redComponent, greenComponent, blueComponent); listBoxMessages.Items.Add("Background color: " + BackColor.Name); int X = (int)selfPlacingWindowKey.GetValue("X"); int Y = (int)selfPlacingWindowKey.GetValue("Y"); this.DesktopLocation = new Point(X, Y); listBoxMessages.Items.Add("Desktop location: " + DesktopLocation.ToString()); this.Height = (int)selfPlacingWindowKey.GetValue("Height"); this.Width = (int)selfPlacingWindowKey.GetValue("Width"); listBoxMessages.Items.Add("Size: " + new Size(Width, Height).ToString()); string initialWindowState = (string)selfPlacingWindowKey.GetValue("WindowState"); listBoxMessages.Items.Add("Window State: " + initialWindowState); this.WindowState = (FormWindowState)FormWindowState.Parse (WindowState.GetType(), initialWindowState); return(true); }
/// <summary> /// Восстановление данных из файла конфигурации. /// </summary> /// <returns></returns> bool ReadSettings() { // Загрузка настроек по парам [ключ]-[значение]. NameValueCollection allAppSettings = ConfigurationManager.AppSettings; if (allAppSettings.Count < 1) { return(false); } // Восстановление состояния: //1. Цвет фона. int red = Convert.ToInt32(allAppSettings["BackGroundColor.R"]); int green = Convert.ToInt32(allAppSettings["BackGroundColor.G"]); int blue = Convert.ToInt32(allAppSettings["BackGroundColor.B"]); this.BackColor = Color.FromArgb(red, green, blue); listBox1.Items.Add("Цвет фона: " + BackColor.Name); //2. Расположение на экране. int X = Convert.ToInt32(allAppSettings["X"]); int Y = Convert.ToInt32(allAppSettings["Y"]); this.DesktopLocation = new Point(X, Y); listBox1.Items.Add("Расположение: " + DesktopLocation.ToString()); //3. Размеры окна. this.Height = Convert.ToInt32(allAppSettings["Window.Height"]); this.Width = Convert.ToInt32(allAppSettings["Window.Width"]); listBox1.Items.Add("Размер: " + new Size(Width, Height).ToString()); //4. Состояние окна. string winState = allAppSettings["Window.State"]; listBox1.Items.Add("Состояние окна: " + winState); this.WindowState = (FormWindowState)FormWindowState.Parse(WindowState.GetType(), winState); return(true); }