asmrobot
2019-11-25 2aeab450471cb80b59002da7da80faf251a0c4f4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RichCreator.Utility.Captures.DesktopDuplication;
 
namespace RichCreator.Utility.Captures
{
    public class DesktopDuplicationCapture : ICapture
    {
        private DesktopDuplicator capture= new DesktopDuplicator(0);
 
        public Bitmap CaptureScreen()
        {
            DesktopFrame frame = null;
            try
            {
                frame = capture.GetLatestFrame();
            }
            catch
            {
 
                return null;
            }
 
            if (frame != null)
            {
                //LabelCursor.Location = frame.CursorLocation;
                //LabelCursor.Visible = frame.CursorVisible;
                //Debug.WriteLine("--------------------------------------------------------");
                //foreach (var moved in frame.MovedRegions)
                //{
                //    Debug.WriteLine(String.Format("Moved: {0} -> {1}", moved.Source, moved.Destination));
                //    MovedRegion.Location = moved.Destination.Location;
                //    MovedRegion.Size = moved.Destination.Size;
                //}
                //foreach (var updated in frame.UpdatedRegions)
                //{
                //    Debug.WriteLine(String.Format("Updated: {0}", updated.ToString()));
                //    UpdatedRegion.Location = updated.Location;
                //    UpdatedRegion.Size = updated.Size;
                //}
 
                //bool black = true;
                //Color b = Color.FromArgb(0, 0, 0);
                //for (int y = 0; y < 2; y++)
                //{
                //    for (int x = 0; x < 2; x++)
                //    {
                //        if (frame.DesktopImage.GetPixel(x, y) != b)
                //        {
                //            black = false;
                //        }
                //    }
                //    if (!black)
                //    {
                //        break;
                //    }
                //}
 
 
                //if (black)
                //{
                //    black = false;
                //}
                if (frame.UpdatedRegions.Length <= 0)
                {
                    return null;
                }
                return frame.DesktopImage;
            }
            return null;
        }
 
        public Bitmap CaptureScreen(int x, int y, int width, int height)
        {
            using (Bitmap screen = CaptureScreen())
            {
                if (screen == null)
                {
                    return null;
                }
                Bitmap screenRect = screen.Clone(new Rectangle(x, y, width, height), screen.PixelFormat);
                return screenRect;
            }
            
        }
    }
}