当前位置:网站首页>The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different
The native applet uses canvas to make posters, which are scaled to the same scale. It is similar to the uniapp, but the writing method is a little different
2022-06-24 09:07:00 【Secret Shura】
Finally, look at the rendering directly ; Don't bullshit , Go straight to the code , design sketch .
( Four file copies can be used directly , The code has comments )
Ideas : When we use iphone6/7/8 At the time of foundation , You'll see Get the width of the screen as 350, High for 603, This is the screen data obtained by the wechat development tool . 1、 Picture in canvas When , You can set the height first , Width and width . 2、 When your canvas When you need to put it on the screen of other mobile phones , You need to use other mobile phones wide /iphone678 wide high /iphone678 high Get it ( Zoom in or out ) The proportion of .3、 Then multiply by the width of the picture 、 high 4、 The width and height of the text should be set just like the picture
js↓↓↓↓↓↓ file :
// pages/manage/myshare/painter.js
Page({
/**
* Initial data of the page
*/
data: {
var foo = 'bar';
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad: function (options) {
},
/**
* Life cycle function -- Listening page first rendering completed
*/
// canvas.js
onReady: function (e) {
},
sening: function(e) {
var that = this;
wx.getSystemInfo({
success: function(res) {
console.log(res.windowHeight)
console.log(res.windowWidth)
console.log(res.pixelRatio)
let windowscale = res.windowHeight/res.windowWidth;
console.log(windowscale)
// Put the data in data
that.setData({
windowHeight: res.windowHeight,
windowWidth: res.windowWidth,
windowscale:windowscale,
psScal:res.windowWidth/350,// wide // With iphone6/7/8 Based on width and height . You can use other , Scale
psScal1:res.windowHeight/603// high // With iphone6/7/8 Based on width and height . You can use other , Scale
})
},
})
var windowWidth = Number(that.data.windowWidth);
var windowHeight = Number(that.data.windowHeight);
// console.log(windowWidth*2)
var wscale = that.data.windowscale;
console.log(windowHeight)
const ctx = wx.createCanvasContext('shareImg')
// The main thing is to calculate the position of each picture and text
// Green picture of the head
var psScal = windowWidth/350
var psScal1 = windowHeight/603
// Print aspect ratio
console.log(psScal)
console.log(psScal1)
let topGreen = '../../../images/beijing212.jpg';
ctx.drawImage(topGreen, 0, 0, psScal*270, psScal1*270)
// QR code picture
let botWhite = '../../../images/qcm.jpg';
ctx.drawImage(botWhite, psScal*170,psScal1*320, psScal*100, psScal1*100)
/***
// Set text size **
****/
ctx.setTextAlign('center')
ctx.setFontSize(15)
ctx.fillStyle = '#fff';
var hedetxt = '';
// Fill in the text
ctx.fillText(hedetxt, psScal*254 / 2, psScal1*200)
// Set text size
ctx.setTextAlign('center')
ctx.setFontSize(13)
ctx.fillStyle = '#333';
var hedbt = ' A thousand miles away is a kiss , Communication with love !';
// Fill in the text
ctx.fillText(hedbt, psScal*254 / 2, psScal1*290)
ctx.setTextAlign('left')
ctx.setFontSize(20)
ctx.fillStyle = '#1F2C3A';
var position = "";
var chr = position.split(""); //that.data.arr.title This method splits a string into an array of strings
var temp = "";
var row = [];
for (var a = 0; a < chr.length; a++) {
if (ctx.measureText(temp).width < windowWidth + 50) {
temp += chr[a];
} else {
a--; // Here added a-- To prevent character loss , There's a contrast in the renderings
row.push(temp);
temp = "";
}
}
row.push(temp);
// If the array length is greater than 2 Then intercept the first two
if (row.length > 2) {
var rowCut = row.slice(0, 3);
// This parameter can determine how many lines are displayed
var rowPart = rowCut[1];
var test = "";
var empty = [];
for (var a = 0; a < rowPart.length; a++) {
if (ctx.measureText(test).width < windowWidth) {
test += rowPart[a];
} else {
break;
}
}
empty.push(test);
var group = empty[0] // Only two lines are shown here , Use the excess ... Express
rowCut.splice(1, 1, group);
row = rowCut;
}
for (var b = 0; b < row.length; b++) {
ctx.fillText(row[b], psScal*26, psScal1*(320 + b * 50));
}
// // Set text size
// ctx.setTextAlign('center')
// ctx.setFontSize(26)
// ctx.fillStyle = '#1F2C3A';
// var rtt = ' I am reading this article , Recommended to you ';
// // Fill in the text
// ctx.fillText(rtt, 540 / 2 + 68, 590)
// 1、 Set text size
ctx.setFontSize(34)
console.log("psScal*34")
console.log(psScal*34)
ctx.fillStyle = '#1dacf9';
var rbc = ' Rui ';
// Fill text and set position
ctx.fillText(rbc, psScal*20, psScal1*330)
// 2、 Set text size
ctx.setFontSize(34)
ctx.fillStyle = '#1dacf9';
var rbc = ' navigation ';
// Fill text and set position
ctx.fillText(rbc, psScal*60, psScal1*355)
// 3、 Set text size
ctx.setFontSize(12)
ctx.fillStyle = '#aaa';
var rct = ' Applet code ';
// Fill text and set position
ctx.fillText(rct, psScal*40, psScal1*400)
// 4、 Set text size
ctx.setFontSize(12)
ctx.fillStyle = '#aaa';
var rbl = ' Qianhang Bairui ,';
// Fill text and set position
ctx.fillText(rbl,psScal*5, psScal1*415)
// 5、 Set text size
ctx.setFontSize(12)
ctx.fillStyle = '#aaa';
var rbr = ' Walk with love ';
// Fill text and set position
ctx.fillText(rbr, psScal*80, psScal1*415)
ctx.draw()
},
/**
* Life cycle function -- Monitor page display
*/
onShow: function () {
this.sening()
},
/**
* Life cycle function -- Monitor page hidden
*/
onHide: function () {
},
/**
* Life cycle function -- Monitor page uninstall
*/
onUnload: function () {
},
/**
* Page related event handler -- Monitor user pull-down action
*/
onPullDownRefresh: function () {
},
/**
* Handling function of page pull bottom event
*/
onReachBottom: function () {
},
/**
* Users click the upper right corner to share
*/
onShareAppMessage: function () {
}
})
.wxml↓↓↓↓↓↓↓ file
<view style="background-color:rgba(0,0,0,0.2);width:100vw;height: 100vh;box-sizing: border-box;">
<!-- canvas.wxml psScal*psScal*-->
<view class="box-ps">
<canvas class="canvas" style="width:{
{psScal*270}}px;height:{
{psScal1*425}}px" canvas-id="shareImg" ></canvas>
<view class="bottom">
<view class="arrow0"> preservation </view>
<view class="arrow1"> Cancel </view>
</view>
</view>
</view>
.wxss↓↓↓↓↓↓↓ file
/* pages/manage/myshare/painter.wxss */
.canvas{
background-color: #fff;
border: 1rpx solid rgba(0,0,0,0.3);
margin:0 auto;
}
.box-ps{
width:100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
/* justify-content: space-around; */
height:auto;
padding: 70rpx;
margin:0 auto;
box-sizing: border-box;
}
.bottom{
display: flex;
flex-direction: row;
margin-top: 70rpx;
width: auto;
box-sizing: border-box;
justify-content: space-around;
}
.arrow0{
text-align: center;
border-radius: 30rpx;
/* margin-left: 50rpx; */
width: 130rpx;
font-size: 14px;
padding: 13rpx 40rpx;
background-color: #2fa5ff;
color: #fff;
}
.arrow1{
text-align: center;
border-radius: 30rpx;
width: 130rpx;
/* margin-right: 50rpx; */
font-size: 14px;
padding: 13rpx 40rpx;
background-color: #2fa5ff;
color: #fff;
}
json↓↓↓↓↓↓↓↓ file
{
"usingComponents": {
"painter":"/components/painter"
}
}
See the effect picture here ↓↓↓↓↓↓↓↓↓↓↓↓↓:
边栏推荐
- I heard that you are still spending money to buy ppt templates from the Internet?
- MySQL——SQL语句
- 十二、所有功能实现效果演示
- Yolox backbone -- implementation of cspparknet
- 陆奇:我现在最看好这四大技术趋势
- [Niuke] convert string to integer
- 2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
- [pytoch basic tutorial 31] youtubednn model analysis
- 阿里资深软件测试工程师推荐测试人员必学——安全测试入门介绍
- 【牛客】把字符串转换成整数
猜你喜欢

Matlab camera calibrator camera calibration

MySQL | view notes on Master Kong MySQL from introduction to advanced

cookie加密 4 rpc方法确定cookie加密

The form image uploaded in chorme cannot view the binary image information of the request body

4274. suffix expression

Remote connection of raspberry pie without display by VNC viewer

Redis implements a globally unique ID

110. 平衡二叉树-递归法

Leetcode -- wrong set

Linux (centos7.9) installation and deployment of MySQL Cluster 7.6
随机推荐
Solution: Nan occurs in loss during model training
4274. suffix expression
【Redis实现秒杀业务①】秒杀流程概述|基本业务实现
Webrtc series - network transmission 5: select the optimal connection switching
【LeetCode】541. 反转字符串 II
【LeetCode】541. Reverse string II
Idea another line shortcut
On the routing tree of gin
[noi Simulation Competition] send (tree DP)
110. balanced binary tree recursive method
[pytorch basic tutorial 30] code analysis of DSSM twin tower model
threejs辉光通道01(UnrealBloomPass && layers)
Redis实现全局唯一ID
Common emoticons
Essay - Reflection
China chip Unicorn Corporation
解决:jmeter5.5在win11下界面上的字特别小
4275. Dijkstra sequence
KaFormer个人笔记整理
Liunx change the port number of vsftpd