From 0dcd742a3c35527386a93e1b1ef761c2aeff8308 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 2 Mar 2020 23:30:34 +0200 Subject: Implemented Tango.RemoteDesktop. Implemented png 8 bit quantization. Implemented RasterFrame bounds clipping. Refactored VectorFrame to use indexed colors. --- .../CaptureMethods/BitBltScreenCapture.cs | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs (limited to 'Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs') diff --git a/Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs b/Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs new file mode 100644 index 000000000..d8f1e214c --- /dev/null +++ b/Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.RemoteDesktop.CaptureMethods +{ + /// + /// Represents a BitBlt screen capture method. + /// + /// + public class BitBltScreenCapture : ICaptureMethod + { + #region Win32 API Screen shot calls + + // Win32 API calls necessary to support screen capture + [DllImport("gdi32", EntryPoint = "BitBlt", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] + private static extern int BitBlt(int hDestDC, int x, int y, int nWidth, int nHeight, int hSrcDC, int xSrc, + int ySrc, int dwRop); + + [DllImport("user32", EntryPoint = "GetDC", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] + private static extern int GetDC(int hwnd); + + [DllImport("user32", EntryPoint = "ReleaseDC", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] + private static extern int ReleaseDC(int hwnd, int hdc); + + #endregion + + /// + /// Gets the desktop bitmap. + /// + /// The capture region. + /// + public Bitmap GetDesktopBitmap(CaptureRegion region) + { + const int SRCCOPY = 13369376; + + Bitmap bitmap = new Bitmap(region.Width, region.Height); + + using (Graphics g = Graphics.FromImage(bitmap)) + { + // Get a device context to the windows desktop and our destination bitmaps + int hdcSrc = GetDC(0); + IntPtr hdcDest = g.GetHdc(); + + // Copy what is on the desktop to the bitmap + BitBlt(hdcDest.ToInt32(), 0, 0, region.Width, region.Height, hdcSrc, 0, 0, SRCCOPY); + + // Release device contexts + g.ReleaseHdc(hdcDest); + ReleaseDC(0, hdcSrc); + } + + return bitmap; + } + + /// + /// Releases unmanaged and - optionally - managed resources. + /// + public void Dispose() + { + //Do nothing. + } + } +} -- cgit v1.3.1