Beispiel #1
0
 public static extern bool GetCursorInfo(out PCURSORINFO cinfo);
        /// <summary>
        ///     Frame capture timer tick
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void frameCaptureTimer_Tick(object sender, EventArgs e)
        {
            var fileName = String.Format("{1}\\img{0}.png", index++, saveLoc);

            //use the location of the form (x,y)
            var leftPt = //new Point(this.Location.X, this.Location.Y);
                new Point(screenViewMP.Location.X, screenViewMP.Location.Y);

            using (var bmp = new Bitmap(screenViewMP.Bounds.Size.Width, screenViewMP.Bounds.Size.Height))
            {
                using (var g = Graphics.FromImage(bmp))
                {
                    g.CopyFromScreen(leftPt.X, leftPt.Y, 0, 0, screenViewMP.Bounds.Size, CopyPixelOperation.SourceCopy);

                    var cinfo = new PCURSORINFO
                    {
                        Size = Marshal.SizeOf(typeof (PCURSORINFO))
                    };

                    if (Win32Api.GetCursorInfo(out cinfo))
                    {
                        if (cinfo.Flags == Win32Api.CURSOR_SHOWING)
                        {
                            Win32Api.DrawIcon(g.GetHdc(), cinfo.ScreenPos.x, cinfo.ScreenPos.y, cinfo.Cursor);
                            g.ReleaseHdc();
                        }
                    }
                }

                try
                {
                    //encoder.AddFrame(bmp);
                    bmp.Save(fileName);
                }
                catch (Exception ex)
                {
                    log.Error("unable to save bitmap", ex);
                }
            }
        }
 public static extern bool GetCursorInfo(out PCURSORINFO cinfo);