Meet us at PRINT 19. Chicago, IL. Oct. 3 - 5.
This documentation is for the old version. Go to the latest Graphics Mill docs

Bitmap.LockBits Method

Locks a entire bitmap and returns BitmapData object which provides direct access to pixels (without copying).

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

Syntax

Visual Basic
Public Function LockBits As BitmapData
C#
public BitmapData LockBits()

Return Value

BitmapData object which provides direct access to pixels.

Remarks

This method returns BitmapData for all pixels of this bitmap. If you need to work only with a part of bitmap, you should use some overloaded method which takes a rectangle coordinates as arguments.

Examples

C#
Aurigma.GraphicsMill.BitmapData bitmapData = bitmap.LockBits();

unsafe
{
    byte* pos;
    byte* scan0 = (byte*)(bitmapData.Scan0.ToPointer());
    int stride = bitmapData.Stride;

    int widthInBytes = bitmapData.Width * bitmapData.BitsPerPixel / 8;
    int height = bitmapData.Height;

    for (int j = 0; j < height; j++)
    {
        pos = scan0 + stride * j;
        for (int i = 0; i < widthInBytes; i++)
        {
            *pos = (byte)(255 - *pos);
            pos++;
        }
    }
}

bitmap.UnlockBits(bitmapData);

See Also

Reference