Creating a Webcam class
To grant the app access to your camera, build a Webcam
class to host the camera’s main capabilities by creating a webcam.js
file in the src
directory:
The Webcam
constructor accepts two elements: WebcamElement
(videoElement
) and CanvasElement
. The adjustVideoSize()
method adjusts the video element to be proportionate to the size you specified when creating videoElement
.
Now add the other methods to the Webcam
class, as follows:
The setup()
function initializes the camera from the browser and assigns the video stream to your VideoElement
in the component. That means granting access to the camera and returning the videoStream
function to you.
Here are the methods for capturing images:
The _drawImage()
method takes the existing frame in videoElement
when that function is called and displays the image on canvasElement
. The _drawImage()
method is then called in the takeBlobPhoto()
and takeBase64Photo()
methods to handle binary large object (blob) images or Base64 images, respectively.
Last updated