In Chapter 7 we saw that the Bitmap class provides the LockBits and UnlockBits methods, but we didn’t get to use them. LockBits and UnlockBits lock and unlock bitmap pixels in system memory. Each call to LockBits should be followed by a call to UnlockBits.
Why might you want to lock bitmap pixels? Rendering (painting) bitmaps and images is a resource-consuming operation, and it is one of the most frequently performed graphics operations. Suppose you want to change the color or intensity level of a bitmap. You could always loop though the bitmap pixel by pixel and use SetPixel to modify its properties, but that is a huge time- and resource-consuming operation.
The code used in this chapter uses classes defined ...