canvas截图功能

本文介绍如何利用canvas实现网页截图,并基于截取的图片进行二次截取。通过设置不同层级的canvas元素,结合CSS定位实现截图区域的选择与编辑。提供了相关的样式代码作为示例。
摘要由CSDN通过智能技术生成

canvas实现截图并且基于截取的图片进行二次截取

canvas截图转载于

  1. canvas截图

      <div class="mark" id="mark">
            <div id="clip-img-w" class="img_box" ref="bigImage" @mousewheel.stop="rollImg(swiperImgInfo.imgUrl)">
                <img id="cropperImg" :src="swiperImgInfo.imgUrl" alt="" style="width: 100%" @mousedown="move"/>
                <canvas id="drawcanvas"></canvas>
                <canvas id="clipcanvas"></canvas>
            </div>
        </div>
      	<el-button plain type="primary" size="small" @click="handleAddDefect()" class="add-defect">绘制截图</el-button>
    
    
    
    handleAddDefect() {
        console.log(this.rollImgWidth,this.rollImgHeight)
        this.cutShow = true;
        var thiz = this;
        document.getElementById('clipcanvas').style.zIndex = 4;
        var cropperImg = document.getElementById("cropperImg");
        var wrap = document.getElementById("clip-img-w");
        var width = cropperImg.offsetWidth;
        var height = cropperImg.offsetHeight;
        var clipcanvas = document.getElementById("clipcanvas");
        var drawcanvas = document.getElementById("drawcanvas");
        clipcanvas.width = cropperImg.width;
        clipcanvas.height = cropperImg.height;
        drawcanvas.width =cropperImg.width;
        drawcanvas.height = cropperImg.height;
        console.log(clipcanvas.height)
        var clipCtx = drawcanvas.getContext("2d");
        var clipImg = document.createElement("img");
        clipImg.classList.add('img_anonymous');
        clipImg.crossOrigin = "anonymous";
        clipImg.src = thiz.swiperImgInfo.imgUrl;
        var timg = clipImg.cloneNode();
        wrap.appendChild(clipImg);
        clipImg.onload = function(){
            var x = Math.floor((width - this.width)/2);
            var y = Math.floor((height - this.height)/2);
            clipCtx.drawImage(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值