当前位置:网站首页>Applet canvas generate sharing Poster
Applet canvas generate sharing Poster
2022-06-25 19:33:00 【Bin daotianxia】
Finished product rendering : Put the QR code and picture together on a picture . You can scan the following small code to experience .
The location is on the front page of the applet - Upper right corner - Generate Poster .
I made a picture switch .

<!--pages/test/canvas.wxml-->
<block wx:if="{
{urls}} ===../../../images/qrbg.png">
<image src='{
{qrcode}}' class='bgs2' hidden='{
{!hidden}}'></image>
<image src='{
{bg}}' class='bgs' hidden='{
{!hidden}}'></image>
</block>
<!-- The canvas size is customized on demand Here I set it according to the size of the background picture -->
<canvas canvas-id="shareImg" hidden='{
{cvsdis}}' style="width:750px;height:1136px"></canvas>
<!-- The preview area -->
<view hidden='{
{hidden}}' class='preview'>
<image src='{
{prurl}}' class='bcimg' bindtouchstart='timestart' bindtouchend='timeend' bindtap='saveImg'></image>
<button type='primary' size='mini' bindtap='save'> Save to album </button>
</view>
<view class='share' bindtap='qie'> Change the style </view>
<button class='share2' type='primary' bindtap='share' disabled='{
{cvsdis}}'> Generate share map </button>
/* pages/canvas/canvas.wxss */
page{
background: #ededed;
}
canvas{
position: fixed;
top: 0;
left: 800rpx;
}
.share{
position: fixed;
bottom: 0;
width: 50%;
left:0;
height: 100rpx;
line-height: 100rpx;
border-radius: 0;
background: #fff;
color: #42b035;
text-align: center;
}
.share2{
position: fixed;
bottom: 0;
width: 50%;
right: 0;
height: 100rpx;
line-height: 100rpx;
border-radius: 0
}
.preview {
width: 100%;
height: 100%;
background: rgba(0,0,0,.9);
position: absolute;
z-index: 2;
}
.preview image{
width: 80%;
position: absolute;
top: 10%;
left: 10%;
z-index: 3;
border: 1px dashed #fff;
}
.bcimg{
position: absolute;
width: 70%;
height: 76%;
top: 0;
}
.preview button{
width: 100%;
position: fixed;
bottom: 0;
height: 100rpx;
line-height: 100rpx;
left: 0;
border-radius: 0;
z-index: 999999;
}
.bgs{
width: 600rpx;
height: 1050rpx;
position: fixed;
top: 0;
left: 75rpx;
}
.bgs2{
width: 160rpx;
height: 160rpx;
position: fixed;
top: 860rpx;
right: 100rpx;
z-index: 9999;
}var app = getApp();
Page({
data: {
hidden: true,
numbers:1,
i: 0,
img_url:' Address of the interface ',
cvsdis:true,
},
onShow: function (options) {
var that = this;
request.request(
'mp_qrcode', {
bg: that.data.numbers,
},
function (res) {
if (res.data.err == 0) {
that.setData({
bg: that.data.img_url + res.data.data.bg,
qrcode: that.data.img_url + res.data.data.qrcode,
numbers: that.data.numbers + 1,
})
let promise1 = new Promise(function (resolve, reject) {
wx.getImageInfo({
src: that.data.img_url + res.data.data.qrcode,
success: function (res) {
resolve(res);
}
})
});
let promise2 = new Promise(function (resolve, reject) {
wx.getImageInfo({
src: that.data.img_url + res.data.data.bg,
success: function (res) {
resolve(res);
}
})
});
Promise.all([
promise1, promise2
]).then(res => {
console.log(' Look before splicing 1', res)
const ctx = wx.createCanvasContext('shareImg')
// The main thing is to calculate the position of each picture and text
ctx.drawImage(res[0].path, 521, 930, 198, 172)
ctx.drawImage(res[1].path, 0, 0, 750, 1136)
ctx.stroke()
ctx.draw()
that.setData({
cvsdis: false
})
})
}
}
)
},
qie: function () {
var that = this;
var i = that.data.i
that.setData({
cvsdis: true
})
request.request(
'mp_qrcode', {
bg: that.data.numbers,
},
function (res) {
console.log(res.data);
if (res.data.err == 0) {
that.setData({
bg: that.data.img_url + res.data.data.bg,
qrcode: that.data.img_url + res.data.data.qrcode,
numbers: that.data.numbers + 1,
})
let promise1 = new Promise(function (resolve, reject) {
wx.getImageInfo({
src: that.data.img_url + res.data.data.qrcode,
success: function (res) {
resolve(res);
}
})
});
let promise2 = new Promise(function (resolve, reject) {
wx.getImageInfo({
src: that.data.img_url + res.data.data.bg,
success: function (res) {
resolve(res);
}
})
});
Promise.all([
promise1, promise2
]).then(res => {
console.log(' Look before splicing 2', res)
const ctx = wx.createCanvasContext('shareImg')
// The main thing is to calculate the position of each picture and text
ctx.drawImage(res[0].path, 521, 930, 198, 172)
ctx.drawImage(res[1].path, 0, 0, 750, 1136)
ctx.stroke()
ctx.draw()
that.setData({
cvsdis:false
})
})
}
}
)
},
/**
* Generate share map
*/
share: function () {
var that = this
wx.showLoading({
title: ' Effort generation ...'
})
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 740,
height: 1334,
destWidth: 740,
destHeight: 1334,
canvasId: 'shareImg',
success: function (res) {
that.setData({
prurl: res.tempFilePath,
hidden: false
})
console.log(' Living '+that.data.prurl);
wx.hideLoading()
},
fail: function (res) {
console.log(res)
}
})
},
/**
* Save to album
*/
timestart: function (e) {
var _this = this;
_this.setData({ timestart: e.timeStamp });
},
// Click the end time
timeend: function (e) {
var _this = this;
_this.setData({ timeend: e.timeStamp });
},
// Save the picture
saveImg: function (e) {
var that = this;
var times = that.data.timeend - that.data.timestart;
if (times > 300) {
console.log(" Long press ");
console.log(that.data.prur)
wx.saveImageToPhotosAlbum({
filePath: that.data.prurl,
success(res) {
wx.showModal({
content: ' Pictures saved to album , Let's sun it quickly ~',
showCancel: false,
confirmText: ' Good da ',
confirmColor: '#72B9C3',
success: function (res) {
if (res.confirm) {
console.log(' The user clicks ok ');
that.setData({
hidden: true
})
}
}
})
}
})
}
},
save: function () {
var that = this
// In the production environment Remember to add the code to get the photo album authorization
console.log(that.data.prur)
wx.saveImageToPhotosAlbum({
filePath: that.data.prurl,
success(res) {
wx.showModal({
content: ' Pictures saved to album , Let's sun it quickly ~',
showCancel: false,
confirmText: ' Good da ',
confirmColor: '#72B9C3',
success: function (res) {
if (res.confirm) {
console.log(' The user clicks ok ');
that.setData({
hidden: true
})
}
}
})
}
})
}
})It should be noted that :
The background picture is a png chart . The QR code is transparent !( The following style )

边栏推荐
- Overview and trend analysis of China's CT examination equipment industry in 2021 [figure]
- R language uses the model of DALEX package_ The profile function interprets the relationship between a continuous feature and the target value Y in multiple classification models based on the conditio
- Record Baidu search optimization thinking analysis
- Lilda Bluetooth air conditioning receiver helps create a more comfortable road life
- QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]
- Tcp/ip test questions (V)
- Tcp/ip test questions (III)
- Miner's Diary: why should I go mining on April 5, 2021
- LeetCode-78-子集
- Divine reversion EA
猜你喜欢

Vulnhub range - the planes:venus

Print 1 cute every 100 milliseconds ~ with a running lantern effect

One night I worked as an XPath Terminator: XPath Helper Plus

什么是算子?
![Analysis on development status and development suggestions of e-commerce industry in Xinjiang in 2020 [figure]](/img/d1/8ed2958ef365e17494bade6e29ee04.jpg)
Analysis on development status and development suggestions of e-commerce industry in Xinjiang in 2020 [figure]

Guangzhou Sinovel interactive creates VR Exhibition Hall panoramic online virtual exhibition hall

Kotlin compose terminate todo project Click to edit and modify todo

广州华锐互动打造VR展厅全景在线虚拟展厅
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2

Ali vision AI training camp-day01
随机推荐
Alicloud centos8.0 installing mysql8
Laravel validation rule followed Role of auth:: id()
六、HikariConfig的配置解析
广州华锐互动打造VR展厅全景在线虚拟展厅
Tcp/ip test questions (4)
Randomly generate 100 non repeating numbers between 1 and 150 and put them in the array
【历史上的今天】6 月 25 日:笔记本之父诞生;Windows 98 发布;通用产品代码首次商用
一、HikariCP获取连接流程源码分析一
R language plot visualization: plot visualization of two-dimensional histogram contour (basic 2D histogram contour)
PHP little knowledge record
Convert word to PDF through libreoffice
Gbpnzd firm offer for 14 months, simulation for 19 months, test stable
Mail monitoring cloud script execution progress
Divine reversion EA
System optimization method
Elastic high-performance computing on the cloud supports the rapid development of the life science industry, reducing costs and increasing efficiency
Google SEO external chain releases 50+ website platform sharing (e6zzseo)
Guangzhou Sinovel interactive VR panorama brings development to all walks of life
Ali vision AI training camp-day01
Trend ea- fixed stop loss and profit per order