I got what A.J tried to say. It's about implementing
IDisposable
in
LockBitmap
.
Basically, it involves changing:
public class LockBitmap
to:
public class LockBitmap : IDisposable
The constructor:
public LockBitmap(Bitmap source)
{
this.source = source;
}
to:
public LockBitmap(Bitmap source)
{
this.source = source;
LockBits();
}
and create a new method:
public void Dispose()
{
UnlockBits();
}
So, the class usage will change from this
LockBitmap lockBitmap = new LockBitmap(bmp);
lockBitmap.LockBits();
(...)
lockBitmap.UnlockBits();
to this
using(LockBitmap lockBitmap = new LockBitmap(bmp))
{
(...)
}
more elegant, IMO.