基础库: 1.5.3
iOS
第一次会生成一张透明的图片,后面变正常。
望解答,谢谢~
const ctx = wx.createCanvasContext(‘myCanvas’)
ctx.drawImage(_this.data.imageSrc)
ctx.draw();
setTimeout(function () {
_this.drawAfter()
}, 500);
drawAfter: function () {
var _this = this
var canvasW = _this.data.cutW / _this.data.cropperW * _this.data.imageW / pixelRatio
var canvasH = _this.data.cutH / _this.data.cropperH * _this.data.imageH / pixelRatio
var canvasL = _this.data.cutL / _this.data.cropperW * _this.data.imageW / pixelRatio
var canvasT = _this.data.cutT / _this.data.cropperH * _this.data.imageH / pixelRatio
wx.canvasToTempFilePath({
x: canvasL,
y: canvasT,
width: canvasW,
height: canvasH,
destWidth: canvasW,
destHeight: canvasH,
canvasId: ‘myCanvas’,
success: function (res) {
wx.hideLoading()
// 成功获得地址的地方
console.log(‘生成图片成功:’ + res.tempFilePath)
_this.uploadImg(res.tempFilePath);
}
})
},