From 6488158b9fd003d690eb015cf9a644112a363f71 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 2 Mar 2020 00:10:25 +0200 Subject: Implemented Tango.RemoteDesktop using generic Diff Frame. --- .../Tango.ScreenCapture/DirectBitmap.cs | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Software/Experiments/Tango.RemoteDesktop/Tango.ScreenCapture/DirectBitmap.cs (limited to 'Software/Experiments/Tango.RemoteDesktop/Tango.ScreenCapture/DirectBitmap.cs') diff --git a/Software/Experiments/Tango.RemoteDesktop/Tango.ScreenCapture/DirectBitmap.cs b/Software/Experiments/Tango.RemoteDesktop/Tango.ScreenCapture/DirectBitmap.cs new file mode 100644 index 000000000..fac39cc04 --- /dev/null +++ b/Software/Experiments/Tango.RemoteDesktop/Tango.ScreenCapture/DirectBitmap.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.ScreenCapture +{ + public class DirectBitmap : IDisposable + { + public Bitmap Bitmap { get; private set; } + public Int32[] Bits { get; private set; } + public bool Disposed { get; private set; } + public int Height { get; private set; } + public int Width { get; private set; } + + protected GCHandle BitsHandle { get; private set; } + + public DirectBitmap(int width, int height) + { + Width = width; + Height = height; + Bits = new Int32[width * height]; + BitsHandle = GCHandle.Alloc(Bits, GCHandleType.Pinned); + Bitmap = new Bitmap(width, height, width * 4, PixelFormat.Format32bppPArgb, BitsHandle.AddrOfPinnedObject()); + } + + public void SetPixel(int x, int y, Color colour) + { + int index = x + (y * Width); + int col = colour.ToArgb(); + + Bits[index] = col; + } + + public Color GetPixel(int x, int y) + { + int index = x + (y * Width); + int col = Bits[index]; + Color result = Color.FromArgb(col); + + return result; + } + + public void Dispose() + { + if (Disposed) return; + Disposed = true; + BitsHandle.Free(); + } + } +} -- cgit v1.3.1