Привет, я использую электрон, чтобы сделать снимок экрана всего экрана, и мой код работает хорошо, за исключением того факта, что размер загружаемого снимка экрана слишком мал.
Это функция js, которая делает снимок экрана при нажатии кнопки
renderer.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.info(thumbSize.height);
console.info(thumbSize.width);
let options = {types: ['screen'], thumnailSize: thumbSize};
desktopCapturer.getSources(options,function (error,sources) {
console.info(sources);
if (error) return console.info(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.info(screenShotPath);
fs.writeFile(screenShotPath,source.thumbnail.toPNG(), function (err) {
if (err) return console.info(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.info(maxDimension);
return {
width: maxDimension * window.devicePixelRatio,
height: maxDimension * window.devicePixelRatio
};
}
Снимок экрана хорошо передает рабочую область, но проблема в том, что он слишком мал. Может кто-нибудь подскажет, как его размер увеличить? Прилагаю сгенерированный скриншот.
Возвращенные значения - 1366 и 1366, но все же они кажутся маленькими.
вы получаете какие-либо ошибки, отображаемые в консоли?
Понятно, произошла ошибка с написанием "thumnailSize"
это отображалось в консоли? - рад, что это разрешилось ...
Нет, я ввел код



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


поможет ли этот учебник? ourcodeworld.com/articles/read/280/… - Кстати, вы можете дважды проверить числа, возвращаемые
determineScreenshot()- поскольку это, похоже, влияет на размеры вашего снимка экрана. Специально эта строчка:maxDimension * window.devicePixelRatio(и следующая)