GetPixel performance

Jul 30, 2012 at 6:36 PM


First I would like to thank you guys for a great job. Really saved me a lot of time.

I'm using the WinRT version of WriteableBitmapEx and there is a real performance issue with GetPixel. I saw that you recommend not using it for multiple pixel manipulation but this method is used in RotateFree. I ran an analysis of my code with your source and found that >40% of the time it takes to run RotateFree is used by GetPixel.

GetPixel creates a new BitmapContext for each call and it's the dispose if this object that takes >80% of the GetPixel execution time. I wrote Another GetPixel which istead takes the context already created in RotateFree and that dropped the time on the GetPixel call by almost 90%.

It looks like most of the perfomance hot paths points to dispose of BitmapContext. Eg. 30% of the exec time of Resize is dispose time.

And this is on Windows 8/WinRT.



Jul 31, 2012 at 7:42 AM
Edited Jul 31, 2012 at 7:42 AM

Thanks. Good catch with the GetPixel usage in RotateFree. I removed it and inlined the functionality to speed things up. See code revision:

If you look at BitmapConect you will see that it uses reference counting, so it should reuse the context in the GetPixel call if it's enclosed in a using(BitmapeContext), which is the case of the RotateFree.

It's recommended to wrap  all your draw calls in one big context to minimize the overhead needed to transfer pixels from ARGB to WinRT's BGRA format. See my blog post for details:


private void Draw()
   // Wrap updates in a GetContext call, to prevent invalidation overhead
   using (writeableBmp.GetBitmapContext())
   } // Invalidates on exit of using block


- Rene Schulte