locked
Why does RenderTargetBitmap.RenderAsync() keep throwing ArgumentException?

    Question

  • Hi, I am using RenderTargetBitmap to capture a snapshot of a UIElement in WinRT and save the image file, but the RenderTargetBitmap.RenderAsync() keeps throwing ArgumentException. Below is the code snipet:

                RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
                await renderTargetBitmap.RenderAsync(this.RootGrid);

    in which, RootGrid is the root Grid of current page. The Grid cantais three ListViews and some other stuff. The error message is:

    A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
    Additional information: Value does not fall within the expected range.

    I've done lots of search, but can't find one workaround.

    Any idea would be appreciated!


    Sunday, January 18, 2015 5:37 AM

All replies

  • The code you quote is correct. There is something else about when or where you are calling this that is likely at fault. Can you share on your OneDrive a minimal repro sample which demonstrates the problem?
    Sunday, January 18, 2015 6:08 PM
    Owner
  • Hi, Rob, thanks for the quick reply! Unfortunately it is not so easy to select a minimal repro sample. I call the method in a button click event like this:

    private async void btnSaveToImage_Click(object sender, RoutedEventArgs e)
    {
    }

    and the Grid contains a lot of stuff.

    I just wonder in what circumstance a UIElement can not be qualified as the parameter of RenderAsync() method.

    i.e. is there any special requirement for a UIElement to be the qualified parameter of this method? Thanks!

    Monday, January 19, 2015 3:39 AM