0
A
回答
-1
要专门拍摄全屏幕照片,请使用以下代码(从Electron Demo App中拉出示例)。您可以构建此示例,并使用electron api中的screen,desktopCapturer和rectangle模块自定义代码以获取特定的屏幕/显示,或选择特定的边界框(x/y坐标和像素区域)。
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
}
}
,你可以去这个问题的其他途径有:
- 使用object.getClientRects()在DOM来指定要捕获特定的元素,尽管这将需要它们是什么先见之明。
- 在您的视图中添加事件侦听器,通过mouseClick,mouseMove等“绘制”您想要的形状。此stack overflow question的答案可以根据您的需要进行调整。
+0
谢谢,生病检查一下,看看它是否能解决我的问题,同时如果你帮我实现鼠标选择部分(如问题中的照片) –
+0
如果任何人都可以解释为什么答案没有upvoted,然后downvoted,这将不胜感激。答案解决OP的需要捕获屏幕的内容(如评论中提到的屏幕截图),并提供选项探索绘制选择框的方法。 –
相关问题
- 1. 屏幕区域的选择
- 2. 桌面屏幕捕获目标区域
- 3. 用Python选择屏幕区域
- 4. 在桌面上选择区域矩形
- 5. 如何使用所选屏幕区域的recordRTC节点模块记录桌面屏幕视频?
- 6. 最简单的方法来选择屏幕区域
- 7. 捕捉屏幕的区域
- 8. 如何从视频中选择屏幕区域?
- 9. mac的远程桌面连接 - 没有“选项”来选择屏幕大小
- 10. 登录屏幕上的Windows桌面的屏幕截图
- 11. 选择区域
- 12. Java中的桌面屏幕流式
- 13. AS3 - 桌面屏幕的物理尺寸
- 14. Flash中的屏幕/桌面共享
- 15. 与纹理区域的白色屏幕与一些图像
- 16. 将分区高度设置为桌面屏幕?
- 17. 如何在屏幕上选择一个区域并使用Python调暗非选区域?
- 18. 灰色的桌面屏幕除了c中选定的控件#
- 19. ASP.NET - 获取屏幕特定区域的屏幕截图?
- 20. 屏幕捕获OCR屏幕的特定区域
- 21. 媒体查询用于桌面屏幕和手机屏幕
- 22. 手机屏幕内的可见区域
- 23. 放大屏幕的特定区域
- 24. 屏幕上的阴影区域
- 25. 捕获桌面屏幕QT/C++ WinAPI
- 26. 如何录制桌面屏幕UWP
- 27. 如何桌面屏幕发送到Android
- 28. android桌面布局在屏幕外
- 29. 屏幕保护程序隐藏桌面
- 30. 如何扭曲桌面屏幕
关于上下文没有足够的信息。你只是想在屏幕上绘制选择矩形?什么是“屏幕”是一个电子应用程序的上下文:主窗口?用户的桌面? –
@NoGrabbing“喜欢选择截图”。像剪切工具一样。他并不是指PC上的特定位置。 – Crowes
就像截图的概念一样,它可以在任何地方完成。 –