悬赏一包辣条,通过canvas把一张图片等比例切割成九张。理想很美好现实很骨感?
发布于 7 年前 作者 min23 5605 次浏览 来自 官方Issues

切割核心代码:

var that = this

for (var i = 0; i < 3; i++) {

for (var j = 0; j < 3; j++) {

console.log(i, j)

wx.canvasToTempFilePath({

x: that.data.canvasWidth / 3 * j,

y: that.data.canvasHeight / 3 * i,

width: that.data.canvasWidth / 3,

height: that.data.canvasHeight / 3,

canvasId: ‘myCanvas’,

success(res) {

console.log(res.tempFilePath)

wx.saveFile({

tempFilePath: res.tempFilePath,

success(opt) {

console.log(opt.savedFilePath)

that.setData({

yulan: opt.savedFilePath

})

}

})

}

})

}

}

2 回复

最终只切割了一张图片,就是i=0,j=0,的时候。第一张。

第一步。清除本机的文件缓存,小程序最大的缓存文件为10M

第二步。如果上述还不行。

则需要将 上述的切割换成 队列形式, 利用 promise(队列)来消除执行时间异步导致的问题产生的可能

回到顶部