A slightly nicer way to access a webcam from within a browser. Built by Ryhan.
This should cause the browser to prompt the user about allowing access to the camera.
// Set up and request access to the camera
var camera = new CameraKit();
You can optionally supply an onerror
function that catches when
- the browser does not support native webcam access, or
- the user chose to deny webcam access
var camera = new CameraKit({
onerror: function(){ /* Do something when we couldn't access the camera */ }
});
Call getImage()
on your CameraKit
object. You'll be returned a png encoded as a data url.
// Get a png encoded as a data url...
var new_image = camera.getImage();
// ... and set it as the source of your <img /> element.
some_image_element.setAttribute('src', new_image);
Call getData()
on your CameraKit
object. You'll be returned an ImageData
object containing height, width, and an array of arrays containing rgba values.