0 Star 0 Fork 0

Pan/html5_canvas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
5.7.3-canvas中的视频.html 2.75 KB
一键复制 编辑 原始数据 按行查看 历史
Pan 提交于 2019-10-15 17:03 . canvas中视频的处理
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" width="700" height="394">
<video controls id="myvideo">
<source src="3.mp4" type="video/mp4" />
</video>
</canvas>
<video controls id="myvideo">
<source src="3.mp4" type="video/mp4" />
</video>
<div>
<button id="play">play</button>
<button id="stop">stop</button>
</div>
<script src="jq.js"></script>
<script>
$(function ($) {
var canvas = $('#canvas')
var context = canvas.get(0).getContext('2d')
$('#play').click(function () {
$('#myvideo').get(0).play()
})
$('#stop').click(function () {
$('#myvideo').get(0).pause()
})
$(myvideo).bind('play', function () {
drawCanvas()
})
function drawCanvas() {
if ($('#myvideo').get(0).paused || $('#myvideo').get(0).ended) {
return false
}
context.drawImage($('#myvideo').get(0), 0, 0, 700, 394)
var imageData = context.getImageData(0, 0, canvas.width(), canvas.height())
var pixels = imageData.data
context.clearRect(0, 0, canvas.width(), canvas.height())
var tilsRow = 28
var tilsCol = 50
var tilsWidth = imageData.width / tilsCol
var tilsHeight = imageData.height / tilsRow
console.log(tilsWidth, tilsHeight)
for (var row = 0; row < tilsRow; row++) {
for (var col = 0; col < tilsCol; col++) {
var x = Math.floor(col * tilsWidth + tilsWidth / 2)
var y = Math.floor(row * tilsHeight + tilsHeight / 2)
var pos = x * 4 + y * imageData.width * 4
var r = pixels[pos]
var g = pixels[pos + 1]
var b = pixels[pos + 2]
context.fillStyle = 'rgb(' + r + ',' + g + ',' + b + ')'
// context.fillRect(x - tilsWidth / 2, y - tilsHeight / 2, tilsWidth, tilsHeight)
context.beginPath()
context.arc(x,y,tilsWidth/2,0,Math.PI*2,false)
context.closePath()
context.fill()
}
}
setTimeout(drawCanvas, 1000/60)
}
})
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/codingpan/html5_canvas.git
git@gitee.com:codingpan/html5_canvas.git
codingpan
html5_canvas
html5_canvas
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385