Click here to Skip to main content
15,886,199 members
Articles / Multimedia / Image Processing
Alternative
Tip/Trick

Work with bitmaps faster in C#

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
20 Nov 2011CPOL 14.2K   4   1
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Brazil Brazil
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralYes it's more elegant. Thanks Pin
Vano Maisuradze17-Nov-11 7:34
Vano Maisuradze17-Nov-11 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.