uni微信小程序 下载图片跟文字_uni-app开发微信小程序如何将页面某一View内容生成图片并保存在本地...

执子左

(作者)

drawCanvas() {

uni.showLoading({

title: "loading"

});

var _this = this;

var context = uni.createCanvasContext('playbillCanvas');

context.drawImage(_this.areaImage, 0, 0, uni.upx2px(550), uni.upx2px(750));

context.draw(true);

base64ToPath(_this.qr).then(path => {

context.save();

context.drawImage(path, _this.oldImage.imageX, _this.oldImage.imageY, uni.upx2px(_this.image_size), uni.upx2px(

_this.image_size));

context.restore();

context.draw(true);

}).catch(error => {

console.error(error)

})

context.save();

context.setFontSize(uni.upx2px(_this.textFontSize));

context.setFillStyle(_this.textColor);

context.fillText(_this.message, _this.oldText.textX, _this.oldText.textY+10);

context.restore();

context.draw(true);

setTimeout(function() {

uni.canvasToTempFilePath({

canvasId: 'playbillCanvas',

success: function(res) {

uni.hideLoading();

const imageList = [];

imageList.push(res.tempFilePath);

uni.previewImage({

urls: imageList,

indicator: "default",

loop: false

});

},

fail: function() {

uni.hideLoading();

uni.showToast({

title: "生成海报失败!"

});

}

})

}, 2000);

},

2020-02-12 10:56

你可能感兴趣的:(uni微信小程序,下载图片跟文字)