Bitmap::LockBits Method (Rectangle, ImageLockMode, PixelFormat, BitmapData)
Locks a Bitmap into system memory
Assembly: System.Drawing (in System.Drawing.dll)
[SecurityPermissionAttribute(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::UnmanagedCode)]
public:
BitmapData^ LockBits(
Rectangle rect,
ImageLockMode flags,
PixelFormat format,
BitmapData^ bitmapData
)
Parameters
- rect
- Type: System.Drawing::Rectangle
A rectangle structure that specifies the portion of the Bitmap to lock.
- flags
- Type: System.Drawing.Imaging::ImageLockMode
One of the ImageLockMode values that specifies the access level (read/write) for the Bitmap.
- format
- Type: System.Drawing.Imaging::PixelFormat
One of the PixelFormat values that specifies the data format of the Bitmap.
- bitmapData
- Type: System.Drawing.Imaging::BitmapData
A BitmapData that contains information about the lock operation.
Return Value
Type: System.Drawing.Imaging::BitmapDataA BitmapData that contains information about the lock operation.
| Exception | Condition |
|---|---|
| ArgumentException | PixelFormat value is not a specific bits-per-pixel value. -or- The incorrect PixelFormat is passed in for a bitmap. |
| Exception | The operation failed. |
Use the LockBits method to lock an existing bitmap in system memory so that it can be changed programmatically. You can change the color of an image with the SetPixel method, although the LockBits method offers better performance for large-scale changes.
When calling this method, you should use a member of the System.Drawing.Imaging::PixelFormat enumeration that contains a specific bits-per-pixel (BPP) value. Using System.Drawing.Imaging::PixelFormat values, such as Indexed and Gdi, will throw an System::ArgumentException. Also, passing the incorrect pixel format for a bitmap will throw an System::ArgumentException.
This version of the LockBits method is intended to be used with a flags value of ImageLockMode::UserInputBuffer.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.