Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Work with bitmaps faster in C#

0.00/5 (No votes)
20 Nov 2011 3  
I got what A.J tried to say. It's about implementing IDisposable in LockBitmap.Basically, it involves changing:public class LockBitmapto: public class LockBitmap : IDisposableThe constructor:public LockBitmap(Bitmap source){ this.source = source;}to:public...
I got what A.J tried to say. It's about implementing IDisposable in LockBitmap.

Basically, it involves changing:
C#
public class LockBitmap

to:
C#
public class LockBitmap : IDisposable


The constructor:
C#
public LockBitmap(Bitmap source)
{
    this.source = source;
}

to:
C#
public LockBitmap(Bitmap source)
{
    this.source = source;
    LockBits();
}


and create a new method:
C#
public void Dispose()
{
   UnlockBits();
}


So, the class usage will change from this
C#
LockBitmap lockBitmap = new LockBitmap(bmp);
lockBitmap.LockBits();
(...)
lockBitmap.UnlockBits();

to this
C#
using(LockBitmap lockBitmap = new LockBitmap(bmp))
{
    (...)
}

more elegant, IMO.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here