Bitmap Pixel Access Using Compact Framework

September 29, 2007 — Leave a comment

I’ve been working on a new open source project this past week and had a requirement to get ARGB value of every pixel in the image.  I thought ‘OK easy, just use Bitmap.GetPixel()‘!  At first I was using small images so there was not a problem, but as the size of the image increased, the performance of the application just dropped!


After a little bit of digging around I found the answer right under my nose!  Rob Miles recently wrote an article on Image Manipulation in Windows Mobile 5.0 for the OpenNETCF Community site.  The section that stood out to me was ‘Speeding up Bitmap Access’.  I took the techniques he showed in the article and implemented them in my code.  The result was an average savings of 11.5s to grab the pixel ARGB values.


Here is the original code (average for time for a 324×324 image was 12s):


And here is the new code (average for time for a 324×324 image was 0.5s):


By using unsafe block and directly accessing the bitmap data in memory we save a huge 11.5s on average.  If you want a more detailed explanation on how the code works read the article


For those interested here is the image I was testing with:


No Comments

Be the first to start the conversation.

Leave a Reply