<view class="JuanBu_HaiBao_btn1" @click="savePoster">保存到相册</view>
savePoster() {
// 创建canvas对象
const ctx = uni.createCanvasContext('posterCanvas', this);
// 绘制背景
ctx.setFillStyle('#000');
ctx.fillRect(0, 0, 660, 1050);
// 绘制图片
ctx.drawImage('../../static/index/juanbusrc.png', 0, 0, 660, 1050);
// 绘制文字
ctx.setFontSize(32);
ctx.setFillStyle('#FFF');
ctx.setTextAlign('center');
ctx.fillText(this.HuoListname, 330, 310);
// ... 绘制其他内容
// 绘制二维码
ctx.drawImage(this.YM + this.ewm, 155, 680, 220, 220);
// 绘制完成后执行生成临时图片路径和保存到相册
ctx.draw(false, () => {
uni.canvasToTempFilePath({
canvasId: 'posterCanvas',
success: (res) => {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'success'
});
},
fail: () => {
uni.showToast({
title: '保存失败',
icon: 'none'
});
}
});
}
});
});
},
uniapp开发微信小程序纯代码生成海报
最新推荐文章于 2025-05-20 18:25:00 发布