Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

106
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!