h5端或者小程序端,如何使用canvas绘制视频
7***@qq.com
- 发布:2019-10-21 15:14
- 更新:2020-06-11 11:03
- 阅读:1558
朋也 - https://tomoya92.github.io
为啥不用video标签呢?
-
回复 Vision丶:
getVideoBase64(url) {
return new Promise(function (resolve, reject) {
let dataURL = '';
let video = document.createElement("video");
video.setAttribute('crossOrigin', 'anonymous');//处理跨域
video.setAttribute('src', url);
video.setAttribute('width', 400);
video.setAttribute('height', 240);
video.addEventListener('loadeddata', function () {
let canvas = document.createElement("canvas"),
width = video.width, //canvas的尺寸和图片一样
height = video.height;
canvas.width = width;
canvas.height = height;
canvas.getContext("2d").drawImage(video, 0, 0, width, height); //绘制canvas
dataURL = canvas.toDataURL('image/jpeg'); //转换为base64
resolve(dataURL);
});
})
}2020-06-11 13:23
7***@qq.com (作者)
我在H5端用drawImage传视频进去根本不行还报错,小程序端也是一样,可以提供一下demo吗谢谢
2019-10-21 15:24