Use of the methods SetPixel() and GetPixel() in .Net Framework to access each pixel and modify them makes the processing a lot slower.
Why??
======
Basically as we know .Net is a managed code system which uses managed data.And when we are manupulating images which means we are dealing with these two methods :
1. GetPixel() : Copy the Color of pixel from bitmap.
2. SetPixel() : Change it and write back to bitmap.
When we are modifying each pixel of the entire image these methods are simply locking the entire bitmap and after the editing of pixel is done it is unlocking. As this job is repeated for each pixel it becomes slow.
|
Solution
=======
We can improve this by using LockBits and UnlockBits provided in Bitmap class which enables us talk directly with memory.This is way faster than the SetPixel and GetPixel methods because :
Here we are locking the entire bitmap only once and perform all edit operation and then unlock it.
This will improve the performance significantly.
For more detailed explanation please visit : http://www.bobpowell.net/lockingbits.htm
|