Invalidate not present in WPF

Jun 11, 2014 at 10:16 AM
with the following code
        wbmp = BitmapFactory.New(300, 300);
        IMG1.Source = wbmp;
        BitmapContext bmpc = wbmp.GetBitmapContext();

        // Clear the WriteableBitmap with white color
        wbmp.Clear(Colors.Red);

        wbmp.DrawLine(0, 0, 1000, 1000, Colors.Black);
I can't see nothing on screen and Invalidate is not present in WPF. How can I use the library on FPF?

Best regards
Coordinator
Jun 11, 2014 at 10:43 AM
Edited Jun 11, 2014 at 10:44 AM
You would need to dispose the context. In WPF the bitmap is invalidated when its unlocked. In WBX the this is done in the dispose call. Use it like this:
        wbmp = BitmapFactory.New(300, 300);
        IMG1.Source = wbmp;
        using(BitmapContext bmpc = wbmp.GetBitmapContext())
        {
            // Clear the WriteableBitmap with white color
            wbmp.Clear(Colors.Red);

            wbmp.DrawLine(0, 0, 1000, 1000, Colors.Black);
        }
Jul 8, 2014 at 7:32 AM
teichgraf wrote:
You would need to dispose the context. In WPF the bitmap is invalidated when its unlocked. In WBX the this is done in the dispose call. Use it like this:
        wbmp = BitmapFactory.New(300, 300);
        IMG1.Source = wbmp;
        using(BitmapContext bmpc = wbmp.GetBitmapContext())
        {
            // Clear the WriteableBitmap with white color
            wbmp.Clear(Colors.Red);

            wbmp.DrawLine(0, 0, 1000, 1000, Colors.Black);
        }
I don't think it's needed to manually create the context.
Because a context will be created and disposed in DrawLine function refer to WriteableBitmapEx source code.
Coordinator
Jul 8, 2014 at 7:50 AM
It's recommended to manually create the BitmapContext if you are performing more than one call inside it and if you have a batch of draw calls. You will see a huge performance change since Invalidate is only called once instead of n times.