Crop method very slow on WinRT, fast on WP8

Feb 5, 2013 at 10:44 PM
I wrote an app for both Windows 8 (metro) and Windows Phone 8 that crops an image into many pieces to make a puzzle. (Puzzle Picture... you can search for it if you want.)

Crop works perfectly in both versions, however, the Win RT version is extremely slow compared to the Windows Phone 8 version. I'm not even comparing apples to apples. I'm using a tablet powered by an Intel i5 and it's still being beat by the WP8 crop method. I've actually used the Performance Analyzer and narrowed it down to Crop.

The biggest difference is that the WriteableBitmap uses a regular Stream on WP8, but an IRandomAccessStream on WinRT. Is this the cause of the speed differences? Anyone have an idea how to speed this up?
Coordinator
Feb 6, 2013 at 8:11 AM
Edited Feb 6, 2013 at 8:12 AM
Make sure you are using the latest binaries.
Can you post the whole code snippet? Also note due to the nature of WinRT's WB using BGRA instead of ARGB like all other WB implementations we have to perform a conversation. This happens in the BitmapContext. That's why it's highly recommended to wrap a sequence of WBX calls in a context.
private void Draw()
{
   // Wrap updates in a GetContext call, to prevent invalidation overhead
   using (writeableBmp.GetBitmapContext())
   {
      writeableBmp.Clear();
      DrawPoints();
      DrawBeziers();
   
   } // Invalidates on exit of using block
}
More details here: http://kodierer.blogspot.de/2012/05/one-bitmap-to-rule-them-all.html
  • Rene
Feb 6, 2013 at 11:48 AM
Thank you very much. That was indeed my problem. I wrapped the loop I used to crop the original writeablebitmap in the BitmapContext and now it works perfectly.

Thanks again.