canvas.clip开发工具上没有报错,真机测试会报错
发布于 6 年前 作者 guiyingzhu 2291 次浏览 来自 问答

原始代码:

const ctx = wx.createCanvasContext(‘myCanvas’);

ctx.setFillStyle(‘white’);

ctx.fillRect(res.windowWidth * 0.1, 30, res.windowWidth*0.8, res.windowHeight*0.3);

ctx.clip();

ctx.drawImage(tempFilePaths,res.windowWidth * 0.23, 0, 200, 300)

ctx.draw();

5 回复

wx.chooseImage({

count: 1, // 默认9

sizeType: [‘original’, ‘compressed’], // 可以指定是原图还是压缩图,默认二者都有

sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有

success: function (res) {

that.setData({

isMod: false,

isCut: true,

bgColor: “black”,

tempFilePaths:res.tempFilePaths[0]

})

var tempFilePaths = res.tempFilePaths[0];

wx.getSystemInfo({

success: function (res) {

that.setData({

width: res.windowWidth,

height: res.windowHeight,

lastX: res.windowWidth * 0.23,

lastY: 0

})

ctx.save()

ctx.beginPath()

ctx.setFillStyle(‘white’);

ctx.fillRect(res.windowWidth * 0.1, 30, res.windowWidth*0.8, res.windowHeight*0.3);

ctx.clip();

ctx.drawImage(tempFilePaths,res.windowWidth * 0.23, 0, 200, 300)

ctx.restore()

ctx.draw();

}

})

}

})

wx.chooseImage之后调用的,应该默认在onhide里面吧

toPhoto: function () {

const ctx = wx.createCanvasContext(‘myCanvas’);

var that = this;

wx.chooseImage({

count: 1, // 默认9

sizeType: [‘original’, ‘compressed’], // 可以指定是原图还是压缩图,默认二者都有

sourceType: [‘album’, ‘camera’], // 可以指定来源是相册还是相机,默认二者都有

success: function (res) {

that.setData({

isMod: false,

isCut: true,

bgColor: “black”,

tempFilePaths:res.tempFilePaths[0]

})

var tempFilePaths = res.tempFilePaths[0];

wx.getSystemInfo({

success: function (res) {

that.setData({

width: res.windowWidth,

height: res.windowHeight,

lastX: res.windowWidth * 0.23,

lastY: 0

})

}

})

ctx.save()

ctx.beginPath()

ctx.setFillStyle(‘white’);

ctx.fillRect(that.data.width * 0.1, 30, that.data.width * 0.8, that.data.height * 0.3);

ctx.clip();

ctx.drawImage(that.data.tempFilePaths, that.data.width * 0.23, 0, 200, 300)

ctx.restore()

ctx.draw();

}

})

},

难道是因为不能在.getSystemInfo之后调用吗?

问题不能复现。请确认onHide里面是否调了clip

有大神可以帮助我吗?

回到顶部