暫不支持chrom 。支持safari .其他未測試
先引用 jquery 地址。選用新浪的
復制代碼代碼如下:
www.mb5u.com
<script type="text/Javascript" src="http://lib.sinaapp.com/js/jquery/1.6/jquery.JS"></script>
加一個video標簽
復制代碼代碼如下:
www.mb5u.com
<video id="video" controls="controls">
<source src="1.mp4" />
</video>
然後JS
復制代碼代碼如下:
www.mb5u.com
<script type="text/Javascript">
$().ready(function(){
var video, output;
var scale = 0.25;
var initialize = function() {
output = $("#output");
video = $("#video").get(0);
$("#capture").click(captureImage);
};
var captureImage = function() {
var canvas = document.createElement("canvas");
canvas.width = video.videoWidth * scale;
canvas.height = video.videoHeight * scale;
canvas.getContext('2d')
.drawImage(video, 0, 0, canvas.width, canvas.height);
var img = document.createElement("img");
img.src = canvas.toDataURL();
output.prepend(img);
};
$(initialize);
});
</script>