安卓 Android Canvas clip 无效果
发布于 5 年前 作者 ping51 15953 次浏览 来自 问答
ctx.save()
ctx.beginPath()
ctx.setFillStyle('#fff')
sketchUp.drawCircle(10.533 * vw, res[6])
ctx.setShadow(0, 0.5 * vw, 10, 'rgba(55,75,99,0.15)')
ctx.fill()
ctx.restore()

ctx.save()
ctx.beginPath()
sketchUp.drawCircle(10 * vw, res[6])
ctx.clip()
sketchUp.drawImg(this.avatarUrl, res[6])
ctx.restore()
ctx.draw(true)

_canvasDraw () {
const ctx = this.sketchUp.ctx
 wechat.draw(ctx).then(res => {
this._canvasToFile(ctx)
}).catch(err => {
console.info(err)
wechat.hideLoading()
this.$refs.toast.show('绘图失败,请重新尝试!')
})
},
_canvasToFile (ctx) {
wechat.canvasToTempFilePath({
x: 0,
   y: 0,
   width: this.divW * this.prop,
   height: this.divH * this.prop,
   destWidth: this.divW * this.prop,
   destHeight: this.divH * this.prop,
   canvasId: 'poster',
   fileType: 'jpg'
 }, ctx).then(res => {
wechat.hideLoading()
// wechat.previewImage({urls: [res.tempFilePath]})
   this._upLoadImg(res.tempFilePath)
const path = `/pages/poster-share/poster-share`
   getApp().globalData.imgUrl = res.tempFilePath
this.$router.push({path})
// console.info(res.tempFilePath)
 }).catch(err => {
console.info(err)
wechat.hideLoading()
this.$refs.toast.show('请重新尝试!')
})
/**
* 绘制圆形
* [@param](/user/param) r 半径
* [@param](/user/param) res 盒子的信息
* [@param](/user/param) xAdjust 可调整的偏移量x轴
* [@param](/user/param) yAdjust 可调整的偏移量y轴
* [@private](/user/private)
*/
drawCircle (r, res, xAdjust = 0, yAdjust = 0) {
this.ctx.arc((res.left + this.rPos.left + res.width / 2 + xAdjust) * this.prop, (res.top + this.rPos.top + res.width / 2 + yAdjust) * this.prop, r, 2 * Math.PI)
}

/**
* 绘制图片
* [@param](/user/param) imgUrl  图片路径
* [@param](/user/param) res 盒子信息
* [@param](/user/param) xAdjust 可调整的偏移量x轴
* [@param](/user/param) yAdjust 可调整的偏移量y轴
* [@private](/user/private)
*/
// drawImage(sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
drawImg (imgUrl, res, mode, xAdjust = 0, yAdjust = 0) {
let x = (res.left + this.rPos.left + xAdjust) * this.prop
 let y = (res.top + this.rPos.top + yAdjust) * this.prop
 let w = res.width * this.prop
 let h = res.height * this.prop
 // let dx = x + w / 2
 // let dy = y + y / 2
 // let dw = w
 // let dh = h
 switch (mode) {
case 'widthFix' : {
// dh = res.height
     break
   }
default:
break
 }
// this.ctx.drawImage(imgUrl, x, y, w, h, dx, dy, dw, dh)
 this.ctx.drawImage(imgUrl, x, y, w, h)
}
1 回复

你好,此类问题之前修复过,请更新客户端版本至6.7.0。如若问题还存在,麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

回到顶部