aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.ScreenCapture/DirectBitmap.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Tango.ScreenCapture/DirectBitmap.cs')
-rw-r--r--Software/Visual_Studio/Tango.ScreenCapture/DirectBitmap.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.ScreenCapture/DirectBitmap.cs b/Software/Visual_Studio/Tango.ScreenCapture/DirectBitmap.cs
new file mode 100644
index 000000000..fac39cc04
--- /dev/null
+++ b/Software/Visual_Studio/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();
+ }
+ }
+}