aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/GdiScreenCapture.cs
blob: 92f4403fd2a3c7bee8f780635ab95d46c4826e62 (plain)
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.RemoteDesktop.CaptureMethods
{
    /// <summary>
    /// Represents a standard GDI screen capture method.
    /// </summary>
    /// <seealso cref="Tango.RemoteDesktop.ICaptureMethod" />
    public class GdiScreenCapture : ICaptureMethod
    {
        /// <summary>
        /// Gets the desktop bitmap.
        /// </summary>
        /// <param name="region">The capture region.</param>
        /// <returns></returns>
        public Bitmap GetDesktopBitmap(CaptureRegion region)
        {
            var bitmap = new Bitmap(region.Width, region.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                g.CopyFromScreen(region.Left, region.Top, 0, 0, bitmap.Size, System.Drawing.CopyPixelOperation.SourceCopy);
            }

            return bitmap;
        }

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        public void Dispose()
        {
            //Do nothing
        }
    }
}