locked
How to create a .png file

    Question

  • I would like to port an existing desktop application to a Metro app using Javascript for the UI and a C# class library for the application logic. One of the biggest features of the desktop app involves generating a .PNG file based on user input. Ideally, I would like to include this logic in the C# class library so that I can reuse as much of the original (rather involved) code as possible. However, if I understand correctly, the GDI+ functionality that I used to create the bitmap in the desktop app will not be available. So how do I accomplish this in Metro?

    I see that the Canvas element is intended for graphics display now, and I saw elsewhere in the forum that I can save a Canvas as a .PNG. But it is possible to draw on a WinJS Canvas element from my UI within a C# class library called from JavaScript? If so, how? If not, can I just create a new Canvas object that doesn't correspond to anything in the UI, draw on it, and save it as a .PNG all from within the C# code?

    Thank you in advance for any help you can give.

    Tuesday, November 22, 2011 2:50 AM

Answers

  • Hi Donavan,

    Passing around a canvas object and then drawing on it is not going to work.  There are a couple of options for you.  You could use Direct2D from C++, you could stay in javascript and use SVG or the Canvas directly.

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, November 22, 2011 7:03 PM
    Moderator
  • Hi Hilda,

    Since you are programming in JavaScript, you can write to a canvas object and use that!

    -Jeff


    Jeff Sanders (MSFT)

    Monday, July 23, 2012 11:52 AM
    Moderator

All replies

  • Hi Donavan,

    Passing around a canvas object and then drawing on it is not going to work.  There are a couple of options for you.  You could use Direct2D from C++, you could stay in javascript and use SVG or the Canvas directly.

    -Jeff


    Jeff Sanders (MSFT)
    Tuesday, November 22, 2011 7:03 PM
    Moderator
  • Hi Donavan:

    Is there only a way that developer  creates a new bitmap by using Direct2D? Can not I create a picture by C# in Metro Style App?

    Thanks!

    Hilda

    Saturday, July 21, 2012 9:52 AM
  • Hi Hilda,

    Since you are programming in JavaScript, you can write to a canvas object and use that!

    -Jeff


    Jeff Sanders (MSFT)

    Monday, July 23, 2012 11:52 AM
    Moderator