Esempio n. 1
0
        public static bool Record(int fps, int codec)
        {
            GetWindowRect(ClientCommunication.FindUOWindow(), out RECT lpRect);
            Rectangle screenArea = new Rectangle(lpRect.Left, lpRect.Top, (lpRect.Right - lpRect.Left), (lpRect.Bottom - lpRect.Top));

            foreach (System.Windows.Forms.Screen screen in
                     System.Windows.Forms.Screen.AllScreens)
            {
                screenArea = Rectangle.Union(screenArea, screen.Bounds);
            }

            m_ResX = (lpRect.Right - lpRect.Left) - 5;
            m_ResY = (lpRect.Bottom - lpRect.Top) - 5;

            if (m_ResX % 2 != 0)
            {
                m_ResX--;
            }

            if (m_ResY % 2 != 0)
            {
                m_ResY--;
            }

            string filename;
            string name = "Unknown";
            string path = RazorEnhanced.Settings.General.ReadString("VideoPath");

            if (!Directory.Exists(path))
            {
                path = Path.GetDirectoryName(Application.ExecutablePath);
                RazorEnhanced.Settings.General.WriteString("VideoPath", path);
                Assistant.Engine.MainWindow.VideoPathTextBox.Text = path;
            }

            if (World.Player != null)
            {
                name = World.Player.Name;
            }
            if (name == null || name.Trim() == "" || name.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                name = "Unknown";
            }

            name = String.Format("{0}_{1}", name, DateTime.Now.ToString("M-d_HH.mm"));

            int count = 0;

            do
            {
                filename = Path.Combine(path, String.Format("{0}{1}.avi", name, count != 0 ? count.ToString() : ""));
                count--;                 // cause a - to be put in front of the number
            }while (File.Exists(filename));

            try
            {
                m_recording  = true;
                m_filewriter = new VideoFileWriter();
                m_filewriter.Open(filename, m_ResX, m_ResY, fps, (VideoCodec)codec, 30000000);

                // create screen capture video source
                m_videostream = new ScreenCaptureStream(screenArea, fps);
                // set NewFrame event handler
                m_videostream.NewFrame += new NewFrameEventHandler(video_NewFrame);
                // start the video source
                m_videostream.Start();
                return(true);
            }
            catch
            {
                MessageBox.Show("Video Codec not installed on your system.");
                return(false);
            }
        }