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

uniapp app端水印组件封装 一次引入版

直接上代码

<template><view><canvas canvas-id="myCanvas"style="width: 100vw; height: 100vh;opacity: 0;position: fixed;top: -1000px;"></canvas></view>
</template><script>export default {name: "watermark",data() {return {screenWidth: '',screenHeight: ''};},mounted() {// 获取屏幕宽高this.screenWidth = plus.screen.resolutionWidth;this.screenHeight = plus.screen.resolutionHeight;// 初始化画布this.init()},methods: {show(path) {const view = new plus.nativeObj.View('watermark', {top: '0px',left: '0px',height: '100%',width: '100%',opacity: 0.2});let popupViewContentList = [{src: path,id: "logo",tag: "img",position: {top: "0px",left: "0px",width: this.screenWidth + 'px',height: this.screenHeight + "px",}}]view.draw(popupViewContentList);view.interceptTouchEvent(false)view.show()// uni全局引用 方便个别页面关闭uni.$view = view},init() {let that = thisconst ctx = uni.createCanvasContext('myCanvas', this);// 在 Canvas 上绘制图形、文本等let angleInRadians = -45 * Math.PI / 180;// 将原点移动到画布中心ctx.translate(this.screenWidth / 2, this.screenHeight / 2);// 旋转画布ctx.rotate(angleInRadians);// 绘制透明背景ctx.fillStyle = 'rgba(0, 0, 0, 0)';ctx.fillRect(-100, -1000, this.screenWidth, this.screenHeight);ctx.setFillStyle('#000');ctx.setFontSize(12);for (let i = 0; i < 100; i++) {for (let j = 0; j < 6; j++) {ctx.fillText( new Date(), 300 * j - 600, 40 * i - 1000);}}// ctx.rotate('45')ctx.draw(true, () => {// 画布转换图片uni.canvasToTempFilePath({canvasId: 'myCanvas',fileType: 'png',x: 0,y: 0,width: this.screenWidth,height: this.screenHeight,quality: 1,complete: function(res) {// 创建水印that.show(res.tempFilePath)},});});}}}
</script><style>
</style>
http://www.lryc.cn/news/303218.html

相关文章:

  • 最新Unity游戏主程进阶学习大纲(2个月)
  • NoSQL 数据库管理工具,搭载强大支持:Redis、Memcached、SSDB、LevelDB、RocksDB,为您的数据存储提供无与伦比的灵活性与性能!
  • 基于Spring Boot的多级缓存系统设计
  • k8s-配置与存储-配置管理
  • c语言实现bellman-ford算法
  • socket与rpc的区别
  • 10、内网安全-横向移动域控提权NetLogonADCSPACKDC永恒之蓝
  • 代码随想录算法训练营第三八天 | 动态规划
  • 【ubuntu2004安装N卡驱动】
  • 使用 Docker 安装 Kibana 8.4.3
  • 基于python社交网络大数据分析系统的设计与实现
  • 【设计模式】23种设计模式笔记
  • 编程笔记 Golang基础 009 标识符和关键字
  • vue3中mockjs模拟获取数据
  • element ui 添加自定义方法
  • Hive UDF
  • python Opencv 中绘制图
  • imazing软件安全吗?2024中文永久免费许可证
  • JavaScript:防抖与节流
  • 在Win系统部署WampServer并实现公网访问本地服务【内网穿透】
  • 面试经典150题——单词规律
  • RK3568平台开发系列讲解(Linux系统篇)container_of
  • 回显服务器
  • c#,dotnet, DataMatrix 类型二维码深度识别,OCR,(基于 Halcon)
  • 亿道丨三防平板电脑厂商哪家好丨麒麟系统三防平板PAD
  • 什么是hash冲突?以及解决方案
  • C# CAD交互界面-模态窗体与非模态窗体调用方式
  • 19个Web前端交互式3D JavaScript框架和库
  • PaddleSeg分割框架解读[01] 核心设计解析
  • 新鲜出炉:小巧优雅的 css-in-js库StyledFc