【发布时间】:2021-12-15 01:25:30
【问题描述】:
我有一些代码可以截取屏幕截图并将其存储在变量中。
代码如下:
takeScreenshot() {
desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 800, height: 600 })
.then( (sources: { thumbnail: { toDataURL: () => any; }; }[]) => {
const theimage = sources[0].thumbnail.toDataURL(); // Thumbnail size image
})
}
我现在想将此屏幕截图保存到我的计算机中。
我试过了:
fs.writeFile('myimage.png', this.theimage, function(err: any) {
if (err) {
console.error('Failed to save ' + err);
} else {
console.log('Saved: ' + 'myimage.png');
}
});
但它创建的文件不会作为图像打开。
如何将此捕获保存为图像?
【问题讨论】:
标签: javascript angular electron