asmrobot
2019-11-13 576b92fd82f568572bc4beb125fa0ba0191a602f
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Emgu.CV;
using Emgu.CV.Structure;
 
namespace RichCreator.Utility.Captures
{
    public class ScreenCapture
    {
        private DesktopDuplicationCapture capture = new DesktopDuplicationCapture();
        private BitBltCapture bitCapture = new BitBltCapture();
        private ScreenCapture()
        {}
 
        /// <summary>
        /// 截屏
        /// </summary>
        /// <returns></returns>
        public Bitmap CaptureScreen()
        {
            Bitmap bm= capture.CaptureScreen();
            if (bm == null)
            {
                bm = bitCapture.CaptureScreen();
            }
            return bm;
        }
 
 
        public Image<Rgb, byte> CaptureScreenReturnImage()
        {
            Bitmap bitmap = CaptureScreen();
            Image<Rgb, byte> image = new Image<Rgb, byte>(bitmap);
            return image;
        }
 
        /// <summary>
        /// 截取指定区域
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public Bitmap CaptureScreen(Int32 x,Int32 y,Int32 width,Int32 height)
        {
            using (Bitmap bm = CaptureScreen())
            {
                Bitmap screenRect = bm.Clone(new Rectangle(x, y, width, height), bm.PixelFormat);
                return screenRect;
            }
        }
        
        #region sington
        private static ScreenCapture instance;
        private static object lockHelper = new object();
        public static ScreenCapture Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (lockHelper)
                    {
                        if (instance == null)
                        {
                            instance = new ScreenCapture();
                        }
                    }
                }
                return instance;
            }
        }
        
        #endregion
 
    }
}