Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Electron / Angular save the image grabbed by desktopCapturer

I have some code that takes a screenshot and stores it in a variable.

Here is the code:

takeScreenshot() {
    desktopCapturer.getSources({ types: ['screen'], thumbnailSize: { width: 800, height: 600 })
    .then( (sources: { thumbnail: { toDataURL: () => any; }; }[]) => {
      
      const theimage = sources[0].thumbnail.toDataURL(); // Thumbnail size image


    })
}

I now want to save this screenshot into my computer.

I've tried this:

fs.writeFile('myimage.png', this.theimage, function(err: any) {
        if (err) {
            console.error('Failed to save ' + err);
        } else {
            console.log('Saved: ' + 'myimage.png');
        }
    });

But the file that it creates does not open as an image.

How can I save this capture as an image?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use contents.capturePage([dimensions]) on your main file. if you dont provide dimensions argument it will capture the whole window. This will return a promise with native image, and you can use fs.writeFile to create a new image file.

sample

const {
  app,
  BrowserWindow
} = require('electron');
const fs = require('fs');

const initWindow = () => {
  const window = new BrowserWindow({
    width: 800,
    height: 600,
  });

  window.loadFile('index.html');
  return window;
}

app.once('ready', async () => {
  const window = initWindow();
  const image = await window.webContents.capturePage();
  fs.writeFile('image.png', image.toPNG());
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda