首页 / CANVAS / canvas截屏视频流画面
canvas截屏视频流画面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了canvas截屏视频流画面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2540字,纯文字阅读大概需要4分钟。
内容图文
代码:
// 用canvas 画 video的截图
function GrabImage() {
this.canvas = null;
this.ctx = null;
this.width = 0;
this.height = 0;
this.createCanvas = function(info) {
if (this.canvas != null) {
return;
}
this.canvas = document.createElement('canvas');
this.canvas.setAttribute("width", info.width);
this.canvas.setAttribute("height", info.height);
this.canvas.style.width = info.width + "px";
this.canvas.style.height = info.height + "px";
this.canvas.style.backgroundColor = "gray";
// this.canvas.style.visibility = "hidden";
// this.canvas.style.display= "none";
// document.body.appendChild(this.canvas);
this.ctx = this.canvas.getContext("2d");
this.ctx.fillStyle = "white";
this.width = info.width;
this.height = info.height;
}
this.grab = function(items) {
if (this.ctx == null) {
return;
}
this.ctx.fillRect(0, 0, this.width, this.height);
for (var i = 0; i < items.length; ++i) {
this.ctx.drawImage(items[i].v, items[i].x, items[i].y, items[i].w, items[i].h);
}
}
this.data = function() {
if (this.ctx == null) {
return;
}
return this.canvas.toDataURL("image/jpeg");
}
}
// 截屏---------------------------------------------------------
handleScreenshot: function() {
if (!this.grabimage) {
this.grabimage = new GrabImage();
}
this.grabimage.createCanvas({width:918, height:345});
var dom = [];
if ('123'.indexOf(this.mode)>=0) {
dom = [{v: $('#one-box').find('video')[0], x:153, y:0, w:612, h:345}];
} else if ('456'.indexOf(this.mode) >= 0) {
dom = [{v: $('#two1-box').find('video')[0], x:0, y:45, w:454, h:265},
{v: $('#two2-box').find('video')[0], x:464 , y:45, w:454, h:265}];
} else if (7 == this.mode) {
dom = [{v: $('#three1-box').find('video')[0], x:0, y:0, w:612, h:345},
{v: $('#three2-box').find('video')[0], x:622, y:0, w:294, h:167},
{v: $('#three3-box').find('video')[0], x:622, y:177, w:294, h:167}];
}
this.grabimage.grab(dom);
var res = this.grabimage.data();
// console.log('s'+res );
let aLink = document.createElement("a");
aLink.style.display = "none";
aLink.href = res;
aLink.download = "截屏.jpg";
// 触发点击-然后移除
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink);
// html2canvas(document.getElementsByClassName('right1-box1')[0], {
// useCORS: true,
// }).then(canvas => { // {backgroundColor: 'blue'}
// var imgData = canvas.toDataURL("image/png");
// let aLink = document.createElement("a");
// aLink.style.display = "none";
// aLink.href = imgData;
// aLink.download = "截屏.png";
// // 触发点击-然后移除
// document.body.appendChild(aLink);
// aLink.click();
// document.body.removeChild(aLink);
// });
},
内容总结
以上是互联网集市为您收集整理的canvas截屏视频流画面全部内容,希望文章能够帮你解决canvas截屏视频流画面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。