电子截图太小了

时间:2018-05-30 18:31:05

标签: javascript electron

您好我正在使用电子截取整个屏幕的截图,我的代码运行良好,但下载屏幕截图的尺寸太小这一事实除外。

这是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.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

0 个答案:

没有答案