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. 用Python選擇屏幕區域
- 2. 捕捉屏幕的區域
- 3. mac的遠程桌面連接 - 沒有「選項」來選擇屏幕大小
- 4. 登錄屏幕上的Windows桌面的屏幕截圖
- 5. 選擇區域
- 6. Flash中的屏幕/桌面共享
- 7. Java中的桌面屏幕流式
- 8. AS3 - 桌面屏幕的物理尺寸
- 9. 與紋理區域的白色屏幕與一些圖像
- 10. 將分區高度設置爲桌面屏幕?
- 11. 灰色的桌面屏幕除了c中選定的控件#
- 12. ASP.NET - 獲取屏幕特定區域的屏幕截圖?
- 13. 屏幕上的陰影區域
- 14. 放大屏幕的特定區域
- 15. 屏幕保護程序隱藏桌面
- 16. android桌面佈局在屏幕外
- 17. 捕獲桌面屏幕QT/C++ WinAPI
- 18. 如何錄製桌面屏幕UWP
- 19. 如何扭曲桌面屏幕
- 20. MySQL選擇區域
- 21. 選擇區域OpenCV
- 22. 屏幕方向更改後頁面右側的空白區域
- 23. 如何在Linux中抓取選定的屏幕區域?
- 24. 在AS3中選擇屏幕
- 25. ABAP - 在選擇屏幕
- 26. 複選框選擇區域
- 27. UIWebView:跟蹤屏幕更新(髒區域)
- 28. iPhone屏幕截圖特定區域
- 29. 用TextInputLayout填充整個屏幕區域
- 30. C#打印屏幕預定義區域
關於上下文沒有足夠的信息。你只是想在屏幕上繪製選擇矩形?什麼是「屏幕」是一個電子應用程序的上下文:主窗口?用戶的桌面? –
@NoGrabbing「喜歡選擇截圖」。像剪切工具一樣。他並不是指PC上的特定位置。 – Crowes
就像截圖的概念一樣,它可以在任何地方完成。 –