Bit Lock and Cloning

Can anyone familiar with GDI shed some light on why the next sequence is rushing?

var b = new Bitmap("some file");
var bd= b.LockBits(rect , readonly, px); //correct size and pixel type

var clone = (Bitmap)b.Clone();
var cd = clone.LockBits(rect , readonly , px);  //okay

clone.UnlockBits(cd); //okay

b.UnlockBits(bd); //throws -- why?

It does not rush if I clone before blocking the first bitmap that I expected.

I would also expect that if it allows you to clone a locked image, and then allows you to lock / unlock a clone, this will not affect the original.

+2
source share
1 answer

I think that Bitmap.Clone()does not make a deep copy and the data is shared.

Change By following the tips below, move the line immediately after the cloning var band do the following: var clone = new Bitmap(b);. Now it works.

+4
source

Source: https://habr.com/ru/post/1568577/


All Articles