欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 高考 > uni-app canvas创建画布

uni-app canvas创建画布

2025/2/25 1:27:36 来源:https://blog.csdn.net/Edwin_jade/article/details/139642345  浏览:    关键词: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);
                });

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词