当前位置:网站首页>Wechat applet uses canvas drawing, round avatar, network background, text, dotted line, straight line
Wechat applet uses canvas drawing, round avatar, network background, text, dotted line, straight line
2022-07-28 22:30:00 【Summer thought】
<canvas type="2d" id="shareCanvas0" style="height: 1196rpx;width:578rpx;position: fixed;z-index: -100; left: -99999rpx"></canvas>
// mapping
getCanvas(index){
var self=this;
console.log(' mapping ')
const query = wx.createSelectorQuery();
query.select("#shareCanvas0")
.fields({
node: true,
size: false
}).exec((res) => {
const canvas = res[0].node;
const ctx = canvas.getContext('2d');
canvas.width = 1144;
canvas.height = 2392;
self.setData({
drawing: true,
})
new Promise(function (resolve) {
// Draw a background picture
wx.getImageInfo({
src: self.data.posterBg, // Network picture
success(res) {
const img = canvas.createImage();
img.src = res.path;
img.onload = () => {
ctx.drawImage(img, 0, 0, 1144, 2392);
resolve(true);
}
}
})
}).then(function () {
return new Promise(function(resolve){
// Draw names
ctx.font ="500 56px Arial";
ctx.fillStyle = '#343434';
ctx.fillText(app.globalData.student.name, 260, 104)
resolve(true);
})
}).then(function () {
return new Promise(function(resolve){
// Draw names
ctx.font ="400 40px Arial";
ctx.fillStyle = '#9A9A9A';
ctx.fillText(' I invite you to experience the following physical fitness live class ~', 256, 176)
resolve(true);
})
}).then(function () {
return new Promise((resolve)=>{
let posterimg=self.data.images[index].img;
console.log(index, self.data.images)
wx.getImageInfo({
src: posterimg, // Network picture . Poster picture
success(res) {
const img = canvas.createImage();
img.src = res.path;
img.onload = () => {
ctx.drawImage(img, 36, 244, 1076, 1628);
resolve(true);
}
}
})
})
}).then(function () {
return new Promise(function(resolve){
// Get QR code
shareQr().then(res=>{
self.setData({
base64Qr:'data:image/png;base64,' + res//base64 Two dimensional code
})
// Draw qr code
const qrImg = canvas.createImage();
qrImg.src = self.data.base64Qr;
qrImg.onload = () => {
ctx.drawImage(qrImg, 784, 1976, 320, 320);
resolve(true);
}
qrImg.onerror = (err) => {
console.log(err);
resolve(true)
}
})
})
}).then(function () {
return new Promise(function(resolve){
// Draw a dotted line
ctx.save();
ctx.setLineDash([3,6]);
ctx.lineWidth = 4;
ctx.strokeStyle = '#e3e3e3';
ctx.beginPath();
ctx.moveTo(96, 1936);
ctx.lineTo(1040, 1936);
ctx.stroke();
resolve(true);
})
}).then(function () {
return new Promise(function(resolve){
// Draw text
ctx.font ="500 56px Arial";
ctx.fillStyle = '#343434';
ctx.fillText(' Value experience ', 63.6, 2108)
ctx.fillText(' element ', 480, 2108)
ctx.font ="500 132px Arial";
ctx.fillStyle = '#FF7A00';
ctx.fillText('9.9', 300, 2108)
ctx.font ="500 56px Arial";
ctx.fillStyle = '#343434';
ctx.fillText(' Experience value ', 63.6, 2276)
ctx.font ="500 96px Arial";
ctx.fillStyle = '#FF7A00';
ctx.fillText('299', 300, 2276)
ctx.font ="500 56px Arial";
ctx.fillStyle = '#343434';
ctx.fillText(' Yuan's live course ', 460, 2276)
resolve(true);
})
}).then(function () {
return new Promise(function(resolve){
// Sets the color of the line
ctx.save();
ctx.beginPath();
ctx.setLineDash([3,0]);
ctx.strokeStyle = "#FF7A00";
ctx.moveTo(300, 2240);
// Set the end coordinates of the line
ctx.lineTo(460, 2240);
// Set the thickness of the line
ctx.lineWidth = "4";
// Style both ends of the line ( Line cap ) butt | round | square
ctx.lineCap = "round";
// Draw lines ( Draw a figure by tracing )
ctx.stroke();
ctx.restore();
resolve(true);
})
}).then(function () {
// Draw your head
return new Promise(function(resolve){// Draw a round border for your avatar
let avatar = app.globalData.student.avatar || app.oss_pic_prefix_url + "/wechat/static/student.png"
wx.getImageInfo({
src: avatar, // Network picture
success(res) {
const avatarImg = canvas.createImage();
avatarImg.src = res.path;
avatarImg.onload = () => {
ctx.save();
ctx.beginPath();
ctx.arc(124, 116, 80, 0, Math.PI * 2, false);
ctx.clip();
ctx.drawImage(avatarImg, 44, 36, 160, 160);
ctx.restore();
// console.log(' Draw your head ')
resolve(true);
}
}
})
})
}).then(function () {
return new Promise(function(resolve){
// console.log(' Finished drawing , Convert to picture ')
self.transferCanvasToImage(canvas, index)
resolve(true);
})
}).catch((err) => {
console.log(err)
self.setData({
drawing: false,
})
self.data.loading && wx.hideLoading()
})
})
},// Export the content of the specified area of the current canvas to generate a picture of the specified size
transferCanvasToImage(canvas, index) {
const self = this;
wx.canvasToTempFilePath({
canvas: canvas,
success(res){
console.log('canvas Share picture address ', res.tempFilePath)
self.data.loading && wx.hideLoading()
self.setData({
loading: false,
drawing: false
})
self.setData({ canvasImg0: res.tempFilePath})
}
})
},边栏推荐
- HCIP(12)
- Establishment of Ruiji takeout development environment
- HCIP(11)
- CDN working principle
- elment-plus图标input上面带的图标为什么不显示
- Use webworker to perform background tasks
- 成立不到一年!MIT衍生量子计算公司完成900万美元融资
- 98. Verify binary search tree (medium binary search tree DFS)
- [CS231N]Lecture_ 2:Image Classification pipelin
- How to realize dynamic route switching and route caching in vuejs
猜你喜欢

想要快速成长,先要经历重大打击!

Add DNS server to LAN for domain name resolution

【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络

普源示波器实际的使用效果怎么样

IFLYTEK written examination
![[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints](/img/37/7cb5fa3a9078a5f5947485147c819d.png)
[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
![[Ruiji takeout project]day4 - dish management](/img/2a/2d9deb7a583aa37b38a67ef2c74ee7.png)
[Ruiji takeout project]day4 - dish management

Ruiji takeout project - development of business development function Day2

Intranet penetration learning (III) horizontal movement of domain - planning tasks

Which is the file transfer command in the basic services of the Internet
随机推荐
纪念一下第一次写的线段树了喽(对应洛谷3372)
Lvs+keepalived high availability deployment practical application
ssh 免密码登录
微信小程序剪切图片的功能
ECMASript 5/6 笔记
Overall introduction of Ruiji takeout project
76. Minimum coverage substring (hard sliding window hash table string)
Common commands of NPM
How about the actual use effect of common source oscilloscope
[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
tutorial/detailed_workflow.ipynb 量化金融Qlib库
HCIP(14)
示波器发展史中的变化
Analysis notes on let (const) temporary dead zone in JS
Ordinary practice of JS DOM programming
elment-plus图标input上面带的图标为什么不显示
[CVPR 2021] cylinder3d: cylindrical asymmetric 3D convolution network for LIDAR point cloud segmentation
HCIP(15)
CDN working principle
Basic introduction of Rockwell AB PLC rslogix digital quantity IO module