gpt4 book ai didi

javascript - Electron 截图太小

转载 作者:行者123 更新时间:2023-12-05 06:33:42 26 4
gpt4 key购买 nike

您好,我正在使用 electron 截取整个屏幕,我的代码运行良好,但下载的屏幕截图尺寸太小。

点击按钮截图的js函数

渲染器.js:

const electron = require('electron');

const desktopCapturer = electron.desktopCapturer;
const electronScreen = electron.screen;
const shell = electron.shell;

const remote = electron.remote;
const dialog = remote.dialog;

const fs = require('fs');
const os = require('os');
const path = require('path');

const screenshot = document.getElementById('screen-shot');
const screenshotMsg = document.getElementById('screenshot-path');
const pathButton = document.getElementById('path-button');

var screenShotPath ='';

pathButton.addEventListener('click',function (event) {
dialog.showSaveDialog(function (fileName) {
if(fileName == undefined){
return;
}
screenShotPath = fileName;
screenshotMsg.textContent = screenShotPath;
});
});
screenshot.addEventListener('click',function(event){
screenshotMsg.textContent = 'Gathering screens';
const thumbSize = determineScreenshot();
console.log(thumbSize.height);
console.log(thumbSize.width);
let options ={types: ['screen'], thumnailSize: thumbSize};

desktopCapturer.getSources(options,function (error,sources) {
console.log(sources);
if(error) return console.log(error.message);

sources.forEach(function (source) {
if(source.name === "Entire screen" || source.name === "Screen 1" ){
if(screenShotPath === ''){
screenShotPath = path.join(os.tmpdir(),'screenshot.jpeg');
}
console.log(screenShotPath);
fs.writeFile(screenShotPath,source.thumbnail.toPNG(), function (err) {
if(err) return console.log(err.message);

shell.openExternal("file://"+screenShotPath);
var message = 'Saved SS to ' + screenShotPath;
screenshotMsg.textContent = message;
});
}
});
});
});

function determineScreenshot() {
const screensize =electronScreen.getPrimaryDisplay().workAreaSize;
const maxDimension = Math.max(screensize.width,screensize.height);
console.log(maxDimension);

return {
width: maxDimension * window.devicePixelRatio,
height: maxDimension * window.devicePixelRatio
};
}

屏幕截图很好地捕获了工作区域,但问题是它太小了。有人可以告诉我如何增加它的大小吗?我附上生成的屏幕截图。 enter image description here

最佳答案

这可能对你有帮助。

document.getElementById('button').addEventListener('click', () => { // The button which takes the screenshot
desktopCapturer.getSources({
types: ['screen'],
thumbnailSize: {
width: 384,
height: 216
}
}).then( sources => {

}) })

关于javascript - Electron 截图太小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50611348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com