当前位置: 首页 > news >正文

小程序问题

1.获取节点
wx.createSelectorQuery()
wx.createSelectorQuery().in(this) //组件中加in(this),不然获取不到

2.使用实例

wx.createSelectorQuery().in(this).select('#share').fields({node: true,size: true}).exec(async (res) => {const canvas = res[0].node;// Canvas 绘制上下文const ctx = canvas.getContext('2d');//  let dpr = this.data.dpr//画布大小根据屏幕分辨率进行缩放,防止模糊const renderWidth = res[0].widthconst renderHeight = res[0].height// 初始化画布大熊啊//  const dpr = wx.getSystemInfoSync().pixelRatiocanvas.width = renderWidth*ratiocanvas.height = renderHeight*ratioctx.scale(ratio, ratio)//画布背景色ctx.fillStyle="#ffffff"ctx.fillRect(0,0,canvas.width, canvas.height)//画图片const image = canvas.createImage()image.crossOrigin = "Anonymous" // 亚跨域使用image.src = imageCoverimage.onload = ()=>{//计算裁剪图片// const imageWidth = image.width// const imageHeight = image.height// const cropRatio = 3/4// const cropWidth = imageWidth * cropRatio// const cropHeight = imageHeight// 计算裁剪的起始位置,这里以居中为例// const startX = (imageWidth - cropWidth) / 2// const startY = (imageHeight - cropHeight) / 2// ctx.drawImage(image, startX, startY, cropWidth, cropHeight, 0, 0, 300, 400)ctx.drawImage(image, 0, 0, 300, 400);}})

填充文字样式

 ctx.font= '600 12px PingFang TC'ctx.fillStyle = '#ffffff'ctx.fillText('你好',231,362)

填充文字边框样式

 ctx.font= '600 12px PingFang TC'ctx.fillStyle = '#ffffff'ctx.strokeStyle = "#000000";ctx.fillText('你好',231,362)ctx.strokeText('你好',231,362);

计算文字宽度
var metrics = c

ctx.measureText(testLine).width;

3.css文字描边:
-webkit-text-stroke: 1px red; 会使文字越来越瘦,占文字本身的宽度,黑色字体样式会减少在这里插入图片描述

可以使用
data里面设置 textValue: ‘愉快’
在这里插入图片描述

<view class="title-greet" data-color="#0C20E9" data-attr-greet="{{textValue}}">{{textValue}}</view>
.title-greet{-webkit-text-stroke-width: 4px;  -webkit-text-stroke-color: #fff; -webkit-text-stroke: 4px #fff; position: relative;z-index: 1;
}
.title-greet:after {position: absolute;z-index: 2;left: 0;right: 0;top: 0;-webkit-text-stroke-width: 0px;content: attr(data-attr-greet);color: attr(data-color);
}
http://www.lryc.cn/news/398137.html

相关文章:

  • arm 版的 deb、rpm、AppImage 都有什么区别
  • docker中mysql设置lower_case_table_names配置的坑
  • python日志记录工具:loguru日志库使用
  • python入门基础知识·二
  • 深度学习中的正则化技术 - 噪声鲁棒性篇
  • 如何通过 Java 来完成 zip 文件与 rar 文件的解压缩?
  • C 语言中的联合(Union)的用途是什么?
  • 汽车电子助力转向系统研究
  • 大数据学习之 scala基础(补充)
  • 正向传播和反向传播
  • 前端文件下载的方式
  • 视图库对接系列(GA-T 1400)十六、视图库对接系列(本级)通知(订阅回调)
  • Python | Leetcode Python题解之第230题二叉搜索树中第K小的元素
  • Python酷库之旅-第三方库Pandas(018)
  • 九科bit-Worker RPA 内容学习
  • vscode编译环境配置-golang
  • 【JavaEE】网络编程——UDP
  • JAVA毕业设计147—基于Java+Springboot的手机维修管理系统(源代码+数据库)
  • 力扣第228题“汇总区间”
  • 部署大语言模型并对话
  • WebSocket、socket.io-client
  • Maven 仓库
  • 给后台写了一个优雅的自定义风格的数据日志上报页面
  • 【React Native优质开源项目】
  • Android 自动更新时间的数字时钟 TextClock
  • 【Linux Git入门】Git的介绍
  • kafka面试题(基础-进阶-高阶)
  • 《系统架构设计师教程(第2版)》第11章-未来信息综合技术-07-大数据技术概述
  • 前端面试题54(断点续传讲解)
  • YOLOv10改进 | Conv篇 | RCS-OSA替换C2f实现暴力涨点(减少通道的空间对象注意力机制)