Bitmap.Stride Property

Gets the width (in bytes) of the scan line.

Namespace: Aurigma.GraphicsMill
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

C#
public int Stride { get; }

Property Value

The width of the scan line.

Remarks

Since the Width property returns a number of pixels in single scan line, this property contains number of bytes in a scan line. As scan line may be aligned on four-bytes boundary, stride may differ from bitmap data width multiplied on number of bytes per pixel. That's why you should use this property to move to the same position on the next row instead of any other methods.

Examples

C#
using (var bitmap = new Bitmap(@"Images\in.jpg"))
{
    unsafe
    {
        //A pointer to the beginning of the pixel data region
        byte* pointer = (byte*)(bitmap.Scan0.ToPointer());
        //Number of bytes in a row
        int stride = bitmap.Stride;
        //Number of rows
        int height = bitmap.Height;

        for (int i = 0; i < height; i++)
        {
            byte* position = pointer + stride * i;
            for (int j = 0; j < stride; j++)
            {
                //Now we can modify the pixel, for example, invert it
                *position = (byte)(255 - *position);
                position++;
            }
        }
    }
    bitmap.Save(@"Images\Output\out.jpg");
}

See Also

Reference

Manual