在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
参见文档:https://developers.weixin.qq.com/miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html 见下文第21行,不要使用 canvasId,canvas type="2d" 时,传入 canvas 组件实例 ,object类型。 btn_tap(e) {
var that = this;
var img_url = e.currentTarget.dataset.url;
const query = wx.createSelectorQuery();
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
const _canvas = res[0].node;
const ctx = _canvas.getContext('2d');
const dpr = wx.getSystemInfoSync().pixelRatio;
_canvas.width = res[0].width * dpr
_canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr)
ctx.fillRect(0, 0, 480, 640)
let img = _canvas.createImage();
img.onload = () => {
ctx.drawImage(img, 0, 0, 480, 480);
wx.canvasToTempFilePath({
canvas: _canvas,
success: (resx) => {
wx.saveImageToPhotosAlbum({
filePath: resx.tempFilePath,
success: (resxx) => {
wx.showToast({
title: '保存成功',
duration: 1000,
});
}
});
},
fail: (ex) => {
console.log(ex);
}
});
};
img.src = img_url;
});
return;
}
|
请发表评论