Php 调用写字板图片,手机端写字板、画板vue组件

一个简单的canvas写字板、画板vue组件,由于项目需求目前只提供清空功能

代码及demo

使用

1.引入组件

import draw from './inDraw/index'

components: {

draw,

},

2.使用组件,可以放在一个自定义样式的div中

:inRatio="3" //retina屏兼容,画布大小放大倍数,Number

:inLineColor="'#999'" //笔触颜色

:inLineWidth="5" //笔触宽度,Number

:inShadowBlur="5" //笔触阴影大小,Number

>

清空

3.自定义清空按钮,调用组件方法inDeleteCanvas清空画布

methods: {

drawDelete(){

this.$refs["in-draw"].inDeleteCanvas()

},

}

开发笔记

1.需要兼容retina屏一倍图模糊的问题,将画布大小设置为canvas元素的2或3倍

//this.inRatio=3;

let canvasDom=this.$refs['in-draw-canvas'];

this.inCanvasBound = canvasDom.getBoundingClientRect();

canvasDom.width=this.inCanvasBound.width*this.inRatio;

canvasDom.height=this.inCanvasBound.height*this.inRatio;

this.inCtx.lineWidth=10*this.inRatio;

2.笔触锯齿问题,设置阴影

this.inCtx.shadowBlur = 5;

this.inCtx.shadowColor = "#000";

3.适应需求在不同位置的画布,笔触实际位置为当前坐标减去画布位置

let x=(e.changedTouches[0].pageX - this.inCanvasBound.left + 0.5)*this.inRatio;

let y=(e.changedTouches[0].pageY- this.inCanvasBound.top + 0.5)*this.inRatio;

1460000017523266?w=362&h=652

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值