Electron 屏幕截图
2017-06-14 16:21
120 查看
const electron = require('electron') const desktopCapturer = electron.desktopCapturer const electronScreen = electron.screen const shell = electron.shell const fs = require('fs') const os = require('os') const path = require('path') const screenshot = document.getElementById('screen-shot') const screenshotMsg = document.getElementById('screenshot-path') screenshot.addEventListener('click', function (event) { screenshotMsg.textContent = 'Gathering screens...' const thumbSize = determineScreenShotSize() let options = { types: ['screen'], thumbnailSize: thumbSize } desktopCapturer.getSources(options, function (error, sources) { if (error) return console.log(error) sources.forEach(function (source) { if (source.name === 'Entire screen' || source.name === 'Screen 1') { const screenshotPath = path.join(os.tmpdir(), 'screenshot.png') fs.writeFile(screenshotPath, source.thumbnail.toPng(), function (error) { if (error) return console.log(error) shell.openExternal('file://' + screenshotPath) const message = `Saved screenshot to: ${screenshotPath}` screenshotMsg.textContent = message }) } }) }) }) function determineScreenShotSize () { const screenSize = electronScreen.getPrimaryDisplay().workAreaSize const maxDimension = Math.max(screenSize.width, screenSize.height) return { width: maxDimension * window.devicePixelRatio, height: maxDimension * window.devicePixelRatio } }
相关文章推荐
- 实现屏幕截图的代码-Android
- ubuntu系统如何屏幕截图
- 屏幕截图的函数
- 简单演示屏幕窗口截图的两种方法(MessageBox截图,并自动关闭)
- E72i 屏幕截图宝典之百事屏幕截图v2.0
- MFC 屏幕截图
- Java屏幕截图及剪裁
- iphone开发之屏幕截图
- ubuntu屏幕截图工具:scrot,可截鼠标拖曳的矩形区域图形
- php web屏幕截图上传服务器和保存本地功能
- 从FrameBuffer中获取Android屏幕截图
- C#软件开发实例.私人订制自己的屏幕截图工具(七)添加放大镜的功能
- Android 5.0及以上编程实现屏幕截图功能的方法
- ios 屏幕截图
- C#实现类似qq的屏幕截图程序
- 2.4 Gazebo入门-Gazebo捕捉屏幕截图
- C#实现类似qq的屏幕截图程序 [转载]
- C#实现类似qq的屏幕截图程序 [转载]
- java 屏幕截图
- 关于使用getDrawingCache()方法获取屏幕截图的问题