示例#1
0
        public void CaptureProcess(bool showTaskBar)
        {
            Clear();

            var width  = showTaskBar ? Screen.Bounds.Width : Screen.WorkingArea.Width;
            var height = showTaskBar ? Screen.Bounds.Height : Screen.WorkingArea.Height;

            var x = showTaskBar ? Screen.Bounds.X : Screen.WorkingArea.X;
            var y = showTaskBar ? Screen.Bounds.Y : Screen.WorkingArea.Y;

            var screenPixel = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            using (var dest = Graphics.FromImage(screenPixel))
            {
                using (var src = Graphics.FromHwnd(IntPtr.Zero))
                {
                    var hSrcDc = src.GetHdc();
                    var hDc    = dest.GetHdc();
                    BitBlt(hDc, 0, 0, width, height, hSrcDc, x, y, (int)CopyPixelOperation.SourceCopy);
                    dest.ReleaseHdc();
                    src.ReleaseHdc();
                }
            }

            Bitmap  = screenPixel;
            Capture = BitmapHelper.BitmapToImage(CopyBitmap());
        }
        public bool Init()
        {
            if (_filePath != null && File.Exists(_filePath))
            {
                try
                {
                    Bitmap      = new Bitmap(_filePath);
                    BitmapImage = BitmapHelper.BitmapToImage(CopyBitmap());

                    return(true);
                }
                catch (Exception e)
                {
                    Logger.Error(e);
                }
            }

            return(false);
        }