video 添加水印

注意: canvas 必须跟 video 在同一级

	var container = document.getElementById('dPlayerVideo') // 注意水印盒子必须和video同级
    var containerWidth = container.offsetWidth // 获取父容器宽
    var containerHeight = container.offsetHeight // 获取父容器高
    container.style.position = 'relative' // 设置布局为相对布局

    // 创建canvas元素(先制作一块背景图)
    const can = document.createElement('canvas')
    can.width = 390 // 设置每一块的宽度
    can.height = 200 // 高度
    const cans = can.getContext('2d') // 获取canvas画布
    cans.rotate(-20 * Math.PI / 180) // 逆时针旋转π/9
    cans.font = '20px Vedana' // 设置字体
    cans.fillStyle = 'rgba(200, 200, 200, 0.30)' // 设置字体的颜色
    cans.textAlign = 'left' // 文本对齐方式
    cans.textBaseline = 'Middle' // 文本基线
    cans.fillText(model.app.$store.state.user.id, 0, 4 * can.height / 5) // 绘制文字
    // 创建一个div元素
    const div = document.createElement('div')
    div.id = 'vieoWatermark' // 设置id
    div.style.pointerEvents = 'none' // 取消所有事件
    div.style.top = '0px'
    div.style.left = '0px'
    div.style.position = 'absolute'
    div.style.zIndex = '100000'
    div.style.width = `100%`
    div.style.height = '100%'
    div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat'
    container.appendChild(div) // 追加到页面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值