钉钉小程序不用canvas在后端绘图前端用image标签获取图片的实践
公司的需求要用电子员工卡代替用了N久的工作证,在各种场合刷二维码来代替刷卡。在钉钉小程序里实现。感觉这回又要躺坑里了。
钉钉小程序第一次做。我这个自封的GDI+大神才不要想用钉钉jsapi的方式用canvas来实现呢,怎么样,机智不。
我们看一眼官方的demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | example.restore = function (context) { [3, 2, 1].forEach( function (item) { context.beginPath(); context.setStrokeStyle( '#108ee9' ); context.save(); context.scale(item, item); context.rect(10, 10, 100, 100); context.stroke(); context.restore(); }); }; example.drawImage = function (context) { context.drawImage( '/image/api.png' ,100, 50); }; example.fillText = function (context) { context.beginPath(); context.setStrokeStyle( '#108ee9' ); context.moveTo(0, 10); context.lineTo(300, 10); context.stroke(); // context.save(); // context.scale(1.5, 1.5); // context.translate(20, 20); context.setFontSize(10); context.fillText( 'Hello Dingtalk' , 0, 30); context.setFontSize(20); context.fillText( 'Hello Dingtalk' , 200, 30); // context.restore(); context.beginPath(); context.moveTo(0, 30); context.lineTo(300, 30); context.stroke(); }; example.fill = function (context) { context.beginPath(); context.setFillStyle( '#108ee9' ); context.rect(20, 20, 150, 100); context.fill(); }; |
实现的过程:
1)前端:
<view class="page"> <view class="page-section"> <image style="background-color: #eeeeee; width: {{windowWidth}}px; height:{{windowHeight}}px;" mode="aspectFit" src="{{src}}" onError="imageError" onLoad="imageLoad" /> </view> </view>
Page({ data: { src: '', windowHeight:488, windowWidth:298, }, onLoad(query) { dd.getSystemInfo({ success: (res) => { this.setData({ windowHeight:res.windowHeight-32, windowWidth:res.windowWidth-26, src:query.src+'&imageWidth='+(res.windowWidth-26)+'&imageHeight='+(res.windowHeight-26) }); console.log(query.src+'&imageWidth='+(res.windowWidth-26)+'&imageHeight='+(res.windowHeight-26)); } }); }, imageError: function (e) { console.log('image3 发生错误', e.detail.errMsg) }, imageLoad: function (e) { console.log('image 加载成功', e); } });
2)后端(ASP.NET CORE 3.1):
搞定!
作者:数据酷软件
出处:https://www.cnblogs.com/datacool/p/12445373.html
关于作者:20年编程从业经验,持续关注MES/ERP/POS/WMS/工业自动化
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明。
联系方式: qq:71008973;wx:6857740733
基于人脸识别的考勤系统 地址: https://gitee.com/afeng124/viewface_attendance_ext
自己开发安卓应用框架 地址: https://gitee.com/afeng124/android-app-frame
WPOS(warehouse+pos) 后台演示地址: http://47.239.106.75:8080/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探