Beispiel #1
0
        /// <summary>
        /// 开始
        /// </summary>
        /// <param name="frameEventHandler"></param>
        public override void Start(NewFrameEventHandler frameEventHandler = null)
        {
            if (hwnd == IntPtr.Zero)
            {
                MessageBox.Show($"没有找到程序【{programName}】!");
                return;
            }
            //首先获取一张,并设置成此大小
            Bitmap programBmp = WindowApi.GetWindowCapture(hwnd);

            base.ScreenWidth = programBmp.Width % 2 == 0 ? programBmp.Width : programBmp.Width - 1;
            base.ScreenHight = programBmp.Height % 2 == 0 ? programBmp.Height : programBmp.Height - 1;
            //开始录制
            base.Start(null);
            this.frameEventHandler = frameEventHandler;
        }
Beispiel #2
0
        /// <summary>
        /// 捕捉每帧
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected override void VideoStreamer_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap programBmp = WindowApi.GetWindowCapture(hwnd);
            Bitmap newBitmap  = new Bitmap(this.ScreenWidth, this.ScreenHight);

            //修改图片大小
            using (Graphics graphics = Graphics.FromImage(newBitmap))
            {
                graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.DrawImage(programBmp, 0, 0, base.ScreenWidth, base.ScreenHight);
            }
            var newFrameEvent = new NewFrameEventArgs(newBitmap);

            base.VideoStreamer_NewFrame(sender, newFrameEvent);
            try
            {
                frameEventHandler.Invoke(sender, newFrameEvent);
            }
            catch { }
        }