---
title: "Bitmap..::.LockBits Method (Int32, Int32, Int32, Int32)"
canonical: https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Bitmap_LockBits_4_951ae041.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 (Int32, Int32, Int32, Int32)
 
Locks a rectangular area of the 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 ( _left As Integer, _top As Integer, _width As Integer, _height As Integer _
) As BitmapData
```
 
```csharp
public BitmapData LockBits(int left,int top,int width,int height
)
```
 
### Parameters
 
 - left
     - Type: [System.Int32](http://msdn2.microsoft.com/en-us/td2s409d)
X-coordinate of the top left corner of the rectangular area to lock.

 - top
     - Type: [System.Int32](http://msdn2.microsoft.com/en-us/td2s409d)
Y-coordinate of the top left corner of the rectangular area to lock.

 - width
     - Type: [System.Int32](http://msdn2.microsoft.com/en-us/td2s409d)
Width of the rectangular area to lock.

 - height
     - Type: [System.Int32](http://msdn2.microsoft.com/en-us/td2s409d)
Height of the rectangular area to lock.
 
### Return Value
 [BitmapData](https://www.graphicsmill.com/docs/gm5/T_Aurigma_GraphicsMill_BitmapData.htm.md) object which provides direct access to pixels.
 
## Remarks
  
Each call of this method should be followed with subsequent [UnlockBits(BitmapData)](https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Bitmap_UnlockBits_1_ed2555df.htm.md) method call. You cannot lock bits one more time until you unlock them with [UnlockBits(BitmapData)](https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Bitmap_UnlockBits_1_ed2555df.htm.md). You can check if bits are locked with [BitsLocked](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_Bitmap_BitsLocked.htm.md) property.
 
Rectangle parameters are measured in units specified with [Unit](https://www.graphicsmill.com/docs/gm5/P_Aurigma_GraphicsMill_UnitConverterObject_Unit.htm.md) property of the source bitmap.
 
If you want to load all pixels of the bitmap, you can use [overloaded version without arguments](https://www.graphicsmill.com/docs/gm5/M_Aurigma_GraphicsMill_Bitmap_LockBits.htm.md).
 
## Examples
  
```
Console.WriteLine("Bitmap")
Console.WriteLine("  PixelFormat: " & bitmap.PixelFormat.ToString())
Console.WriteLine("  CMYK: " & bitmap.IsCmyk)
Console.WriteLine("  GrayScale: " & bitmap.IsGrayScale)
Console.WriteLine("  RGB: " & bitmap.IsRgb)
Console.WriteLine("  Indexed: " & bitmap.IsIndexed)
Console.WriteLine("  Extended: " & bitmap.IsExtended)

Dim bitmapData As Aurigma.GraphicsMill.BitmapData = bitmap.LockBits(20, 20, 150, 100)

Console.WriteLine("BitmapData")
Console.WriteLine("  PixelFormat: " & bitmapData.PixelFormat.ToString())

bitmap.UnlockBits(bitmapData)
```
 
```csharp
Console.WriteLine("Bitmap");
Console.WriteLine("  PixelFormat: " + bitmap.PixelFormat.ToString());
Console.WriteLine("  CMYK: " + bitmap.IsCmyk);
Console.WriteLine("  GrayScale: " + bitmap.IsGrayScale);
Console.WriteLine("  RGB: " + bitmap.IsRgb);
Console.WriteLine("  Indexed: " + bitmap.IsIndexed);
Console.WriteLine("  Extended: " + bitmap.IsExtended);

Aurigma.GraphicsMill.BitmapData bitmapData = bitmap.LockBits(20, 20, 150, 100);

Console.WriteLine("BitmapData");
Console.WriteLine("  PixelFormat: " + bitmapData.PixelFormat.ToString());

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)
