Skip to content

Commit e7e72f0

Browse files
committed
Updated readme
1 parent 6a9ddf6 commit e7e72f0

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ NuGet: https://www.nuget.org/packages/ScreenCapture.NET
55

66
## Usage
77
```csharp
8-
// Sets the DPI-awareness of the application - this is required for capturing
8+
// Sets the DPI-awareness of the application - this is required for capturing.
99
DPIAwareness.Initalize();
1010

1111
// Create a screen-capture service
@@ -27,29 +27,27 @@ CaptureZone fullscreen = screenCapture.RegisterCaptureZone(0, 0, screenCapture.D
2727
CaptureZone topLeft = screenCapture.RegisterCaptureZone(0, 0, 100, 100, downscaleLevel: 1);
2828

2929
// Capture the screen
30-
// This should be done in a loop on a seperate thread as CaptureScreen blocks if the screen is not updated (still image)
30+
// This should be done in a loop on a seperate thread as CaptureScreen blocks if the screen is not updated (still image).
3131
screenCapture.CaptureScreen();
3232

3333
// Do something with the captured image - e.g. access all pixels (same could be done with topLeft)
3434
// Locking is not neccessary in that case as we're capturing in the same thread,
35-
// but when using a threaded-approach (which is recommended) it prevents potential tearing of the data in the buffer
35+
// but when using a threaded-approach (which is recommended) it prevents potential tearing of the data in the buffer.
3636
lock (fullscreen.Buffer)
3737
{
38-
// Since the size of the capture can be bigger than the size of our captured region due to size constraints on the GPU,
39-
// we need to use this for the stride.
40-
// The 4 is the amount of bytes per pixel which is always 4 for the DX11ScreenCapture
41-
int stride = fullscreen.CaptureWidth * 4;
38+
// Stride is the width in bytes of a row in the buffer (width in pixel * bytes per pixel)
39+
int stride = fullscreen.Stride;
4240

4341
Span<byte> data = new(fullscreen.Buffer);
4442

4543
// Iterate all rows of the image
4644
for (int y = 0; y < fullscreen.Height; y++)
4745
{
4846
// Select the actual data of the row
49-
Span<byte> row = data.Slice(y * stride, fullscreen.Width * 4);
47+
Span<byte> row = data.Slice(y * stride, stride);
5048

5149
// Iterate all pixels
52-
for (int x = 0; x < fullscreen.Width; x += 4)
50+
for (int x = 0; x < row.Length; x += fullscreen.BytesPerPixel)
5351
{
5452
// Data is in BGRA format for the DX11ScreenCapture
5553
byte b = row[x];

0 commit comments

Comments
 (0)