我正在研究找到一种使用Node.js截取窗口截图的方法,我正在尝试使用node-ffi进行此操作,但我不知道如何…我一次我被困在这里:
var ffi = require('ffi');
var user32 = new ffi.Library("user32", {
FindWindowA: [ 'uint32' , [ 'string', 'string' ]]
, PrintWindow: [ 'int32' , [ 'int32', 'string', 'int32' ]]
});
var IMG;
var windowHandle = user32.FindWindowA(null, "Calculator");
var printWin = user32.PrintWindow(windowHandle, IMG, 0);
console.log(printWin);
console.log(IMG);
结果:
$node get-print.js
1
undefined
EDITED
我在C中找到了以下工作代码
Bitmap bm = new Bitmap(1024, 768);
Graphics g = Graphics.FromImage(bm);
IntPtr hdc = g.GetHdc();
Form1.PrintWindow(this.Handle, hdc, 0);
g.ReleaseHdc(hdc);
g.Flush();
g.Dispose();
this.pictureBox1.Image = bm;
现在我需要在NodeJ上做这个,
有人可以帮帮我吗?
解决方法:
您可以使用名为“desktop-screenshot”的NPM包.它使用起来非常简单.
NPM示例:
var screenshot = require('desktop-screenshot');
screenshot("screenshot.png", function(error, complete) {
if(error)
console.log("Screenshot failed", error);
else
console.log("Screenshot succeeded");
});
https://www.npmjs.com/package/desktop-screenshot