---
title: "Bitmap..::.LockBits Method "
canonical: https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Bitmap_LockBits.htm
product: "Graphics Mill 5.5 for .NET"
---

This documentation is for the old version. [Go to the latest Graphics Mill docs](https://www.graphicsmill.com/docs/gm/)

# Bitmap.LockBits Method 
 
Locks a entire bitmap and returns [BitmapData](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_BitmapData.htm.md) object which provides direct access to pixels (without copying).
 
**Namespace:** [Aurigma.GraphicsMill](https://www.graphicsmill.com/docs/gm5/N_Aurigma_GraphicsMill.htm.md)
 **Assembly:** Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)
 
## Syntax
  
```
Public Function LockBits As BitmapData
```
 
```csharp
public BitmapData LockBits()
```
 
### Return Value
 [BitmapData](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_BitmapData.htm.md) object which provides direct access to pixels.
 
## Remarks
 This method returns [BitmapData](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_BitmapData.htm.md) 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
  
```csharp
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

- [Bitmap Class](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_Bitmap.htm.md)
- [LockBits Overload](https://www.graphicsmill.com/docs/gm5/O_T_Aurigma_GraphicsMill_Bitmap_LockBits.htm.md)
- [Aurigma.GraphicsMill Namespace](https://www.graphicsmill.com/docs/gm5/N_Aurigma_GraphicsMill.htm.md)
