Search code examples
c#-4.0image-processingbitmaplockingbitmapdata

What does it actually mean by "Bitmap locking"?


The MSDN says that:

Locks a Bitmap into system memory.

nothing much is explained.

  • What does it actually mean by "Bitmap locking"?

  • How do locking work in the memory?

  • What is the benefit of locking?


Solution

  • It locks the bitmap image (which was not directly accessable except indirectly via the Bitmap class to a memory area so that the you can have direct access to the memory of the image - that is read/write to the image memory directly using a pointer to it.

    You might want to do that if you had to manipulate the image in a way that would be faster by direct access rather than read/writepexel, drawline etc.

    After locking it, you need to remeber to unlock it.

    See the remarks and examples of this MSDN page https://msdn.microsoft.com/en-us/library/5ey6h79d%28v=vs.110%29.aspx