-1

All:

I build a interactive chart app running as node-webkit app. One thing I need help is:

Say if user clicks and the visual of chart changed, how can I use node-webkit to take a screenshot of that page to reflect the change realtime.

Thanks

Kuan
  • 11,149
  • 23
  • 93
  • 201

1 Answers1

3

I'm not sure how a screenshot will help reflect the change in the chart, but here's a function that will take a screenshot of the current nw.js window (visible region only) and store it as a png.

You need to use the Window.capturePage function (further documentation here: https://github.com/nwjs/nw.js/wiki/window#windowcapturepagecallback--image_format-config_object-).

Note that this uses the config_object parameter introduced in v0.9.3 to specify the format as png and to have the image returned in a buffer.

function takeSnapshot() {
    var gui = require('nw.gui');
    var win = gui.Window.get();

    win.capturePage(function(buffer)
    {
        require('fs').writeFile('screenshot.png', buffer, function (err) {
            if (err) throw err;
            console.log('It\'s saved!');
        });

    }, { format : 'png', datatype : 'buffer'} );
}
Simon O'Beirne
  • 316
  • 1
  • 8