locked
RenderTargetBitmap for off-screen rendering?

    Question

  • I'm making an app with a video export function that, among other things, allows you to export presentations to video. I'm rendering the content on-screen, in a canvas, and then using RenderTargetBitmap (giving it the canvas) to create the frame. It actually works great, except -

    RenderTargetBitmap pauses whenever the user navigates away from the app. I assume this is because it uses the UI thread and the UI thread gets suspended when the window is not visible. Meaning, the app must stay in focus for the entire render. This is fine for quick renders, but for longer renders, it would be annoying to tie up the user's computer for an hour or longer.

    Is there any way either to (a) prevent the UI thread from suspending when the user navigates away (thus ensuring RenderTargetBitmap can keep working), or (b) render UIElement's to a bitmap in a worker thread that doesn't get suspended?

    If, as I assume, the answer is no, are there other ways to render text, shapes, and other multimedia content to a bitmap besides using UIElements and RenderTargetBitmap? For example in Win32 you can render text and such to a GDI device-context and then get the bits that way. Is there anything similar for WinRT?

    Thanks much!


    Thursday, May 29, 2014 4:02 PM

Answers

  • Hi Peter,

    What your looking for isn't possible in a Windows Store app. As you note (and as documented) RenderTargetBitmap relies on the tender thread and can only render elements in the foreground visual tree.

    It is not possible to use it in the background or to prevent the app from suspending if the user switches away.

    There are no other API to render UI elements, but some folks have emulated this by parsing the visual ye and rendering the elements themselves with Direct2d
    Thursday, May 29, 2014 4:36 PM
    Owner

All replies

  • Hi Peter,

    What your looking for isn't possible in a Windows Store app. As you note (and as documented) RenderTargetBitmap relies on the tender thread and can only render elements in the foreground visual tree.

    It is not possible to use it in the background or to prevent the app from suspending if the user switches away.

    There are no other API to render UI elements, but some folks have emulated this by parsing the visual ye and rendering the elements themselves with Direct2d
    Thursday, May 29, 2014 4:36 PM
    Owner
  • Yeah, I was hoping there was a way to do this as a background thread that kept running but I guess with the whole app lifecycle being so different from a desktop app this could never work. Even if I rendered using something other than RenderTargetBitmap there'd be nothing I could do about suspension after 10 seconds. Alas - I can at least make it easy to pick up where it left off. Thanks for the quick response!
    Thursday, May 29, 2014 9:38 PM