Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

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

Comments and Discussions

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

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140821.2 | Last Updated 20 Nov 2011
Article Copyright 2011 by danlobo
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid