Capturing Video Frame and then Exporting as Bitmap in HTML5

筅森魡賤 提交于 2019-11-28 18:27:06

Capture the image to a canvas element:

var video  = document.getElementById(videoId);
var canvas = document.createElement('canvas');
canvas.width  = video.videoWidth;
canvas.height = video.videoHeight;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0);

Then use the toDataURL() method to get the image:

canvas.toDataURL('image/jpeg');

Be aware that for all this to work the video has to be from the same origin as the page.

but see this Flash example, where the author encodes a webcam frame in Flash and passes it to Javascript. http://code.google.com/p/flashcam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!