Locks the Bitmap and return the raw data.

Converting between pixel formats is expensive so where possible you should try and use the current pixel format of the Bitmap.

If you specify a pixel format which is different from the current one try and specify ImageLockMode.ReadOnly as this obviates the need to write the pixels back to the original image.

Typically you will want to lock the entire area of the Bitmap, but for convenience you can lock a smaller area using the rect parameter. However it is important to note that the Scan0 property of the returned BitmapData specifies a pointer to a byte, so the left coordinate of the rectangle you provide must be on a byte boundary. If this is not the case an exception will be raised.



BitmapData LockBits(ImageLockMode flags, Rectangle rect, PixelFormat format);

[Visual Basic]

Function LockBits(flags As ImageLockMode, rect As Rectangle, format As PixelFormat) As BitmapData
Name Description
flags Flags indicating the purpose the data is required for.
rect The portion of the bitmap for which pixels should be returned.
format The format of data required.
return The locked data.