canvas实现图片裁剪功能

canvas实现图片裁剪功能

看看效果图吧

代码已经用构造函数和原生方式封闭好了。
附上主要方法:
            //画出背景
            Selection.prototype.drawScene = function () { // main drawScene function
                this.context.drawImage(this.image, 0, 0, this.canvas.width, this.canvas.height);
                this.context.fillStyle = 'rgba(0, 0, 0, 0.5)';
                this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
                // 画出选区
                this.draw();
            }
            //画出选区
            Selection.prototype.draw = function () {
                this.context.strokeStyle = '#fff';
                this.context.lineWidth = 0.5;
                this.context.strokeRect(this.x, this.y, this.w, this.h);
                // 绘制选区图像
                if (this.w > 0 && this.h > 0) {
                    this.context.drawImage(this.image, this.x, this.y, this.w, this.h, this.x, this.y, this.w, this.h);
                }
                // 画出四个角的调整方块
                this.context.fillStyle = 'rgba(255, 255, 255, 1)';
                this.context.fillRect(this.x - this.iCSize[0], this.y - this.iCSize[0], this.iCSize[0] * 2, this.iCSize[0] * 2);
                this.context.fillRect(this.x + this.w - this.iCSize[1], this.y - this.iCSize[1], this.iCSize[1] * 2, this.iCSize[1] * 2);
                this.context.fillRect(this.x + this.w - this.iCSize[2], this.y + this.h - this.iCSize[2], this.iCSize[2] * 2, this.iCSize[2] * 2);
                this.context.fillRect(this.x - this.iCSize[3], this.y + this.h - this.iCSize[3], this.iCSize[3] * 2, this.iCSize[3] * 2);
                this.drawLine();
            }
            //画出九宫格
            Selection.prototype.drawLine = function () {
                this.context.strokeStyle = "#fff";
                this.context.strokeRect(this.x, this.y + parseFloat(this.h / 3), this.w, 0.05);
                this.context.strokeRect(this.x, this.y + parseFloat(this.h / 3) * 2, this.w, 0.05);
                this.context.strokeRect(this.x &
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值