Bitmap.LockBits Method (Rectangle, ImageLockMode, PixelFormat)
Locks a Bitmap into system memory.
Assembly: System.Drawing (in System.Drawing.dll)
[<SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)>] member LockBits : rect:Rectangle * flags:ImageLockMode * format:PixelFormat -> BitmapData
- Type: System.Drawing.Rectangle
- Type: System.Drawing.Imaging.ImageLockMode
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.
The following code example demonstrates how to use the PixelFormat, Height, Width, and Scan0 properties; the and UnlockBits methods; and the ImageLockMode enumeration. This example is designed to be used with Windows Forms. This example is not designed to work correctly with all pixel formats, but to provide an example of how to use the method. To run this example, paste it into a form and handle the form's Paint event by calling the LockUnlockBitsExample method, passing e as PaintEventArgs.
Available since 1.1