最近公司项目在用uni-app做小程序商城,其中商品和个人需要生成图片海报,经过摸索记录后将一些重点记录下来。这里有两种方式来生成
1、后台控制生成
2、前端用canvas合成图片
这里我们只讲使用canvas合成图片的方法
通过createCanvasContext方法来创建画布
var _this = this;
_this.ctx = uni.createCanvasContext(‘canvasid‘, this);
const C_W = uni.upx2px(_this.Width); //canvas宽度
_this.canvasW = C_W;
_this.canvasH = 420;
_this.ctx.setFillStyle(‘#545a7a‘); //canvas背景颜色
_this.ctx.fillRect(0, 0, C_W, _this.canvasH); //canvas画布大小
原文:https://www.cnblogs.com/xiangzhong/p/11937391.html