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

110
Visualizações
Fit video stream in positionned canvas

In a webapp on mobile I display a video stream on full screen (i.e 360 x 520) using .getUserMedia. Depending values passed in URL (i.e 260 x 220) I create a canvas in the middle of the screen:

    let largview = iw-40;                             // canvas width with left 20px (iw=screen width)
    let heightview = Math.round((largview)/w)*h;      // URL values
    let topview = Math.round((ih-heightview)/2);      // (ih=screen height)

    video.style.width = iw+'px';
    video.style.height = ih+'px';
    canvas.width = largview;
    canvas.height = heightview;
    canvas.style.marginLeft = 20+'px';
    canvas.style.marginTop = topview+'px';

Once done I duplicate the video stream in this canvas:

    setInterval(function(){
        context.drawImage(cameraVideo, 20,topview, largview,heightview, 0,0, largview,heightview);
    },1);

My prob is that I'm unable to display the video in canvas just as this one was "transparent": without its border:1px solid red you couldn't see it, video stream and canvas stream will perfectly fit together. I've tried a lot of different values in drawImage but sometimes canvas stream is largest than video stream, sometimes its not at the right place, sometimes its works well (top/left are OK) but canvas is not fully filled: 20px missing on the right side...

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

0

I've found a [weird ?] solution with 2 <canvas> tags:

The 1st canvas is set to width and height = 100% (contains the full video stream).

The 2nd one is sized largview * heightview, with position = 20px left and topview px of the top.

    setInterval(function(){
    
        cameraContext.drawImage(cameraVideo,  0,0,  iw,ih); // full video
        
        let imageData = cameraContext.getImageData( 20, topview, cameraCanvas.width, cameraCanvas.height);
        cameraContext2.putImageData(imageData, 0, 0);
        
    },1);

Works well.

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