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

uni-app canvas创建画布

canvasTmp: function(arr2, store_name, successFn, errFun) {let that = this;const ctx = uni.createCanvasContext('myCanvas');ctx.clearRect(0, 0, 0, 0);/*** 只能获取合法域名下的图片信息,本地调试无法获取* */uni.getImageInfo({			src: arr2[0],success: function(res) {const WIDTH = res.width*0.71;const HEIGHT = res.height*1.04;// const WIDTH = 320;//  const HEIGHT = 450;let r = 70;let d = r * 2;let cx = 85;let cy = 110;ctx.drawImage(arr2[1], 0, 0, WIDTH, HEIGHT); // 小图ctx.save();ctx.arc(cx + r, cy + r, r, 0, 2 * Math.PI);ctx.drawImage(arr2[0], cx, cy, d, d); // 背景ctx.restore();const CONTENT_ROW_LENGTH = 40;let [contentLeng, contentArray, contentRows] = that.textByteLength(store_name, CONTENT_ROW_LENGTH);if (contentRows > 2) {contentRows = 2;let textArray = contentArray.slice(0, 2);textArray[textArray.length - 1] += '……';contentArray = textArray;}ctx.setTextAlign('center');ctx.setFontSize(26); // 文字ctx.setFillStyle('#000000');let contentHh = 26 * 1.3;for (let m = 0; m < contentArray.length; m++) {ctx.fillText(contentArray[m], 156, 430 + contentHh * m);}ctx.setTextAlign('left')ctx.setFontSize(28);ctx.setFillStyle('#FFFFFF');ctx.draw(true, function() {uni.canvasToTempFilePath({canvasId: 'myCanvas',fileType: 'png',destWidth: WIDTH,destHeight: HEIGHT,success: function(res) {uni.hideLoading();successFn && successFn(res.tempFilePath);},fail: function(err) {uni.hideLoading();errFun && errFun(err);}})});},fail: function(err) {uni.hideLoading();that.Tips({title: '无法获取图片信息'});errFun && errFun(err);}})},

调用 : 

async spreadMsg(image ,name, title) {let that = this/** #ifndef H5   type: 'h5',   #endif  #ifdef MP || APP || APP-PLUS  #endif*/let rqData = {type: 'routine'}that.spreadData = [that.bgurl[that.type]]that.nickName = namethat.siteName = titlelet codeUrl = ""// #ifdef MP || APP-PLUSlet mpUrl = await that.downloadFilestoreImage(image)// #endifuni.showLoading({title: '海报生成中',mask: true});// 本来这个是个循环 也就是出现多个海报 去除了let arr2// #ifdef MP || APP-PLUS	arr2 = [mpUrl, await that.downloadFilestoreImage(that.bgurl[that.type])]// #endif// #ifdef H5let img = await that.imgToBase(that.bgurl[that.type])arr2 = [await that.imgToBase(image), img]			// #endifthat.$util.canvasTmp(arr2, name, (tempFilePath) => {that.$set(that.posterImage, 0, tempFilePath);}, (err) => {that.$set(that, 'canvasStatus', false);});uni.hideLoading();},

that.$util.PosterCanvasMer(arr2, name, (tempFilePath) => {
                    that.$set(that.posterImage, 0, tempFilePath);
                }, (err) => {
                    that.$set(that, 'canvasStatus', false);
                });

http://www.lryc.cn/news/374549.html

相关文章:

  • Spring MVC详解(上)
  • 【Linux硬盘读取】Windows下读取Linux系统的文件解决方案:Linux Reader4.5 By DiskInternals
  • 操作系统—页表(实验)
  • github 本地仓库上传及报错处理
  • 【ZZULIOJ】1104: 求因子和(函数专题)
  • 轨迹优化 | 图解欧氏距离场与梯度场算法(附ROS C++/Python实现)
  • 【二维差分】2132. 用邮票贴满网格图
  • 【前端项目笔记】2 主页布局
  • t265 jetpack 6 px4 ros2
  • vue 应用测试(一) --- 介绍
  • Perl 语言入门学习
  • HarmongOS打包[保姆级]
  • SpringBoot怎么实现自定义接口全局异常捕获?详细教程
  • Ms08067安全实验室成功实施多家业务系统渗透测试项目
  • 小熊家政帮day22-day23 订单系统优化(订单状态机、练习分库分表、索引、订单缓存)
  • LeetCode 1731, 151, 148
  • Codeforces Round 953 (Div. 2)(A~D题解)
  • 晶圆切割机(晶圆划片机)为晶圆加工重要设备 我国市场国产化进程不断加快
  • 39、基于深度学习的(拼音)字符识别(matlab)
  • CCF 矩阵重塑
  • Aigtek高压放大器在柔性爬行机器人驱动性能研究中的应用
  • Postman下发流表至Opendaylight
  • C语言王国——数组的旋转(轮转数组)三种解法
  • MySQL中CAST和CONVERT函数都用于数据类型转换
  • 速盾:cdn影响seo吗?
  • 期末算法复习
  • 可穿戴设备:苹果“吃老底”、华为“忙复苏”、小米“再扩容”
  • AI数据分析:集中度分析和离散度分析
  • redis的分布式session和本地的session有啥区别
  • SSH概念、用途、详细使用方法