Click here to Skip to main content
13,093,097 members (76,219 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7.1K views
4 bookmarked
Posted 17 Nov 2011

Work with bitmaps faster in C#

, 20 Nov 2011
Rate this:
Please Sign up or sign in to vote.
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:
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

danlobo
Brazil Brazil
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralYes it's more elegant. Thanks Pin
Vano Maisuradze17-Nov-11 7:34
memberVano 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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 20 Nov 2011
Article Copyright 2011 by danlobo
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid