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

uniapp、小程序canvas相关

  • 1、圆形or圆形头像
//示例
const ctx = uni.createCanvasContext('myCanvas'); //canvas
const round = uni.upx2px(72) / 2; // 半径
const x = uni.upx2px(92); //目标x轴位置
const y = uni.upx2px(236); //目标y轴位置//if 图片是不是静态资源
async =>
const imgSrc = 'https://xxxxxxxxxx';
const imgRes = await uni.getImageInfo({src: imgSrc
});
const url = await imgRes?.path;//else
const imgSrc = '项目静态文件/xxx.png';drawRound(ctx, round, x, y, url); //调用const drawRound = (ctx, round, x, y, img) => {ctx.save();ctx.beginPath();let r = round;let d = 2 * r;let cx = x + r;let cy = y + r;ctx.arc(cx, cy, r, 0, 2 * Math.PI);ctx.clip();ctx.drawImage(img, x, y, d, d);ctx.restore();
};
  • 2、填充背景
const ctx = uni.createCanvasContext('myCanvas'); //canvas
width, height => canvas的width,height
const createCanvasbj = (ctx, width, height) => {ctx.beginPath();ctx.rect(0, 0, width, height);ctx.setFillStyle('#FAFAFA');ctx.fill();
};
  • 3、文字
ctx.setFillStyle('#646978');
ctx.setFontSize(20);
ctx.fillText(123123, x, y);

*4、阴影

const createShadow = () => {ctx.beginPath();ctx.shadowOffsetX = 0;ctx.shadowOffsetY = 5;ctx.shadowColor = '#D4D4D4';ctx.shadowBlur = 10;ctx.rect(x, y, Width, Height);ctx.setFillStyle('#FFFFFF');ctx.fill();
};

*5、圆角矩形

const createRoundedrectangle = ( ctx, tagLeft, tagWidth, tagTop, tagHeight, radius) => {//tagLeft >= x//tagTop >= y//tagHeight => width//radius => 圆角ctx.beginPath();ctx.arc(tagLeft + tagWidth - radius, tagTop + tagHeight - radius, radius, 0, Math.PI * 0.5);ctx.lineTo(tagLeft + radius, tagTop + tagHeight);ctx.arc(tagLeft + radius, tagTop + tagHeight - radius, radius, Math.PI * 0.5, Math.PI);ctx.lineTo(tagLeft, tagTop + radius);ctx.arc(tagLeft + radius, tagTop + radius, radius, Math.PI, Math.PI * 1.5);ctx.lineTo(tagLeft + tagWidth - radius, tagTop);ctx.arc(tagLeft + tagWidth - radius, tagTop + radius, radius, Math.PI * 1.5, Math.PI * 2);ctx.lineTo(tagLeft + tagWidth, tagTop + tagHeight - radius);ctx.closePath();ctx.setStrokeStyle('#E60012');ctx.setFillStyle('#E60012');ctx.fill();
};
http://www.lryc.cn/news/236892.html

相关文章:

  • [工业自动化-23]:西门子S7-15xxx编程 - 软件编程 - 西门子PLC人机界面交互HMI功能概述、硬件环境准备、软件环境准备
  • 在Ubuntu系统中安装VNC并结合内网穿透实现公网远程访问
  • java基础练习缺少项目?看这篇文章就够了(上)!
  • 鸿蒙为什么使用typescript 作为开发语言 而不是 flutter 或者 kotlin
  • Flutter NestedScrollView 、SliverAppBar全解析,悬浮菜单的应用
  • Mongodb 副本集名称重命名
  • C#WPF属性触发器实例
  • Kotlin 核心语法,为什么选择Kotlin ?
  • SpringCloud微服务:Nacos的集群、负载均衡、环境隔离
  • Selenium+Python做web端自动化测试框架实战
  • Linux:安装MySQL服务(非docker方式)
  • C++实现有理数类 四则运算和输入输出
  • 小鸟飞呀飞
  • Unity 场景烘培 ——unity Post-Processing后处理1(四)
  • Burpsuite抓HTTPS证书导入问题
  • python保存文件到zip压缩包中
  • java发送媒体类型为multipart/form-data的请求
  • 自定义类使用ArrayList中的remove
  • 前端面试考核点【更持续新中】
  • linux-docker安装
  • 如何用html css js 画出曲线 或者斜线;
  • 【错误记录】Uncaught TypeError: m.nodeName.toLowerCase is not a function
  • 王颖奇:ONES.ai 上线,以及我的一些思考
  • 将AI技术与VR元宇宙相结合的整体解决方案
  • IPKISS Tutorials 3------绘制矩形版图
  • 为什么需要用高压放大器
  • 前端uniapp生成海报绘制canvas画布并且保存到相册【实战/带源码/最新】
  • 【算法专题】双指针
  • redis运维(七)基础通用命令
  • 搜索引擎ElasticSearch分布式搜索和分析引擎学习,SpringBoot整合ES个人心得