aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-03-02 23:30:34 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-03-02 23:30:34 +0200
commit0dcd742a3c35527386a93e1b1ef761c2aeff8308 (patch)
treed5adb3fee35e73af95fa5d68b5316d25522471de /Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs
parent1a7fb274158f8a0e279aef26206a65fefac8c4c3 (diff)
downloadTango-0dcd742a3c35527386a93e1b1ef761c2aeff8308.tar.gz
Tango-0dcd742a3c35527386a93e1b1ef761c2aeff8308.zip
Implemented Tango.RemoteDesktop.
Implemented png 8 bit quantization. Implemented RasterFrame bounds clipping. Refactored VectorFrame to use indexed colors.
Diffstat (limited to 'Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs')
-rw-r--r--Software/Visual_Studio/Tango.RemoteDesktop/CaptureMethods/BitBltScreenCapture.cs68
1 files changed, 68 insertions, 0 deletions
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
+{
+ /// <summary>
+ /// Represents a BitBlt screen capture method.
+ /// </summary>
+ /// <seealso cref="Tango.RemoteDesktop.ICaptureMethod" />
+ 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
+
+ /// <summary>
+ /// Gets the desktop bitmap.
+ /// </summary>
+ /// <param name="region">The capture region.</param>
+ /// <returns></returns>
+ 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;
+ }
+
+ /// <summary>
+ /// Releases unmanaged and - optionally - managed resources.
+ /// </summary>
+ public void Dispose()
+ {
+ //Do nothing.
+ }
+ }
+}