wx.getImageInfo({
src: url,//服务器返回的图片地址
success: function (res) {
//res.path是网络图片的本地地址
let Path = res.path;
let width = res.width;
let height = res.height;
let w = (width > height) ? height : width;
that.setData({
w: w,
h: w,
})
//let w = width > height ? height : width;
const ctx = wx.createCanvasContext('share1');
ctx.drawImage(Path, (w - width) / 2, (w - height) / 2, width, height)
ctx.save();
console.log(res)
ctx.draw(false, () => {
wx.canvasToTempFilePath({
canvasId: 'share1',
success: function (res) {
that.setData({
[key]: res.tempFilePath,
t2:true
})
},
fail(res) {
console.log(res);
}
})
})
},
fail: function (res) {
//失败回调
}
})
工具正常返回最短边像素X最短边像素图片,
手机返回为长方形图片,并且不完整
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
手机华为