我正在获取一些关于用户屏幕分辨率和屏幕设置的信息。
electron.desktopCapturer.getSources()返回DesktopCapturerSource[],我用它来获取屏幕的缩略图。
electron.screen.getAllDisplays()返回Display[],用于获取屏幕尺寸、旋转等。
两者都是大小相等的数组,其中每个元素表示关于桌面屏幕的不同信息。它们有名称和ids,这两个名称和ids似乎都不匹配对象。我不知道如何准确地将两个对象之间的数据关联起来,以保证我谈论的是同一个屏幕。
发布于 2021-03-23 22:29:46
您可以加入这两个调用,并将来自screen.getAllDisplays()返回的对象的screen.getAllDisplays()与desktopCapturer.getSources()返回的对象的display_id对应起来。
请注意,这是在电子12的MacOS大Sur上试过的,其他操作系统的结果可能不一样。
来自screen.getAllDisplays()的示例输出
[
{
id: 2077748985,
bounds: { x: 0, y: 0, width: 1792, height: 1120 },
workArea: { x: 0, y: 25, width: 1792, height: 1095 },
accelerometerSupport: 'unknown',
monochrome: false,
colorDepth: 30,
colorSpace: '{primaries:BT709, transfer:IEC61966_2_1_HDR, matrix:RGB, range:FULL}',
depthPerComponent: 10,
size: { width: 1792, height: 1120 },
displayFrequency: 59,
workAreaSize: { width: 1792, height: 1095 },
scaleFactor: 2,
rotation: 0,
internal: true,
touchSupport: 'unknown'
}
]来自desktopCapturer.getSources()的示例输出
[
{
"name": "Entire Screen",
"id": "screen:2077748985:0",
"thumbnail": {
"isMacTemplateImage": false
},
"display_id": "2077748985",
"appIcon": null
},
{
"name": "Hello World!",
"id": "window:33637:0",
"thumbnail": {
"isMacTemplateImage": false
},
"display_id": "",
"appIcon": null
},
{
"name": "Hello World!",
"id": "window:33636:0",
"thumbnail": {
"isMacTemplateImage": false
},
"display_id": "",
"appIcon": null
},
{
"name": "Correlating the screen information from electron.desktopCapturer.getSources() and electron.screen.getAllDisplays() - Stack Overflow",
"id": "window:3257:0",
"thumbnail": {
"isMacTemplateImage": false
},
"display_id": "",
"appIcon": null
},
{
"name": "electron-fun — Electron Helper (Renderer) ◂ npm TERM_PROGRAM=Apple_Terminal SHELL=/bin/zsh — 127×68",
"id": "window:32731:0",
"thumbnail": {
"isMacTemplateImage": false
},
"display_id": "",
"appIcon": null
},
{
"name": "Calculator",
"id": "window:32797:0",
"thumbnail": {
"isMacTemplateImage": false
},
"display_id": "",
"appIcon": null
}
]注意,id是: 2077748985,display_id也是: 2077748985。
https://stackoverflow.com/questions/46288487
复制相似问题