From ba5233be6f9250deb90dd7a6ab2fc8e2d9a666c6 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Tue, 5 Sep 2023 20:20:25 +0200 Subject: [PATCH] Added ToArray to Image --- ScreenCapture.NET/Model/Image.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ScreenCapture.NET/Model/Image.cs b/ScreenCapture.NET/Model/Image.cs index a67ba53..f7ca9c8 100644 --- a/ScreenCapture.NET/Model/Image.cs +++ b/ScreenCapture.NET/Model/Image.cs @@ -38,7 +38,7 @@ public readonly ref struct Image [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - if ((x < 0) || (y < 0) || ((x + width) > Width) || ((y + height) > Height)) throw new IndexOutOfRangeException(); + if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0) || ((x + width) > Width) || ((y + height) > Height)) throw new IndexOutOfRangeException(); return new Image(_pixels, _x + x, _y + y, width, height, _stride); } @@ -87,6 +87,13 @@ public readonly ref struct Image } } + public TColor[] ToArray() + { + TColor[] array = new TColor[Width * Height]; + CopyTo(array); + return array; + } + #endregion #region Indexer-Structs