How to generate an image with HTML5 canvas element in a Background Task RRS feed

  • Question

  • I'd like to generate a canvas image in a background task. Therefore document.createElement('canvas') would need to be called.

    But a background task doesn't have the document object. Is it still possible to generate an image in a background task?


    Tuesday, October 16, 2012 7:42 PM


  • A background task in JavaScript runs as a web worker and thus has a worker's global scope. I looked over the worker spec on http://www.w3.org/TR/2012/CR-workers-20120501/ and didn't see anything that would be helpful here, suggesting that a background does not have access to canvas elements. (If someone knows otherwise, or can suggest perhaps a library that create a graphic in a file, please chime in.)

    I'm assuming that your interest in the canvas is to create an image for a tile update or a toast notification? In that case, what's important is generating the image, not necessarily using a canvas per se. If that is the case, it might be possible to achieve what you want using a background task written in C# or C++, where you might have more capabilities for creating a graphic. That is, it is allowable to use background tasks written in other languages because they run independently; you would use information in your appdata (through the Windows.Storage.ApplicationData API) to make information available to app and background task, as appdata is common to all languages. (The JS background task sample actually shows this

    I can't suggest how one would create a graphic in C#/XAML from a background task, but you could ask that specific question in the C#/XAML forum.


    • Marked as answer by Song Tian Monday, October 22, 2012 9:00 AM
    Wednesday, October 17, 2012 2:31 AM