locked
Take App Screenshot using WinJS

    Question

  • Hello,

    I'm building an app using Cordova, which inherently uses WinJS.  For my iOS + Android versions, I've made plugins that allow the user to take a screenshot of the app and then draw on it.  Is there an equivalent API in WinJS to take a screenshot of the app?

    I've found the `Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap` class, and using a separate Xaml/C# test project, I was able to take a screenshot... but My Cordova app isn't using Xaml, and I haven't found an equivalent API for the WinJS side of things yet.  Does this exist, or is there a way to somehow use the class I mentioned from a WinJS app?

    Thanks

    Friday, March 6, 2015 2:34 PM

Answers

  • There isn't a good way to do this.

    Windows Store apps don't have any explicit screenshot API (Windows Phone Store apps do have a phone-only ScreenCapture API) and HTML and JavaScript don't provide a way to render arbitrary HTML to a bitmap (such as Xaml's RenderTargetBitmap). You render the contents of a Canvas or a WebView, but not the page itself.

    Depending on what you have in your HTML you may be able to use a library such as http://html2canvas.hertzen.com/ to traverse the DOM and render it into a Canvas which you can convert to a bitmap with toDataUrl.

    Friday, March 6, 2015 4:19 PM
    Moderator