四川德行天下建设工程有限公司网站,wordpress注册邮箱发送,做网站用什么开发好,北京网站建设维护查看专栏目录 canvas实例应用100专栏#xff0c;提供canvas的基础知识#xff0c;高级动画#xff0c;相关应用扩展等信息。canvas作为html的一部分#xff0c;是图像图标地图可视化的一个重要的基础#xff0c;学好了canvas#xff0c;在其他的一些应用上将会起到非常重…
查看专栏目录 canvas实例应用100专栏提供canvas的基础知识高级动画相关应用扩展等信息。canvas作为html的一部分是图像图标地图可视化的一个重要的基础学好了canvas在其他的一些应用上将会起到非常重要的帮助。 文章目录 示例效果图示例源代码共87行canvas基本属性canvas基础方法 canvas图片上如何设置镂空文字效果呢通过globalCompositeOperation设置就可以。本文设置context.globalCompositeOperation‘destination-out’ 或者context.globalCompositeOperation‘xor’ 也是可以的。
示例效果图 示例源代码共87行
/*
* Author: 大剑师兰特xiaozhuanlan还是大剑师兰特CSDN
* 此源代码版权归大剑师兰特所有可供学习或商业项目中借鉴未经授权不得重复地发表到博客、论坛问答git等公共空间或网站中。
* Email: 2909222303qq.com
* weixin: gis-dajianshi
* First published in CSDN
* First published time: 2024-02-05
*/
templatediv classdjs_containerdiv classtoph3canvas设置图片上镂空文字效果/h3div大剑师兰特, 还是大剑师兰特gis-dajianshi/divh4el-button typeprimary sizemini clickdraw()绘制/el-buttonel-button typedanger sizemini clickclearCanvas()清除/el-button/h4/divdiv classdajianshi canvas iddajianshi refmycanvas width980 height490/canvas/div/div
/template
scriptexport default {data() {return {ctx: null,canvas: null,imageUrl: require(../assets/amierhan.png), // 此图片大小990*496}},mounted() {this.setCanvas()},methods: {clearCanvas() { this.ctx.clearRect(-180, -50, this.canvas.width, this.canvas.height);this.ctx.restore();},setCanvas() {this.canvas document.getElementById(dajianshi);if (!this.canvas.getContext) return;this.ctx this.canvas.getContext(2d);},draw() {this.clearCanvas();this.ctx.save();this.ctx.translate(180,50);const image new Image();image.src this.imageUrl;image.addEventListener(load, () {this.ctx.drawImage(image, 0, 0, 600, 350);this.ctx.globalCompositeOperation destination-out;this.ctx.font bold 120px SimHei, STHeiti;this.ctx.fillText(阿米尔.汗, 25, 300);});},}}
/script
style scoped.djs_container {width: 1000px;height: 680px;margin: 50px auto;border: 1px solid #181;position: relative;}.top {margin: 0 auto 0px;padding: 10px 0;background: #181;color: #fff;}.dajianshi {margin: 5px auto 0;border: 1px solid #ccc;width: 980px;height: 490px;background:#ccc;}
/style
canvas基本属性
属性属性属性canvasfillStylefilterfontglobalAlphaglobalCompositeOperationheightlineCaplineDashOffsetlineJoinlineWidthmiterLimitshadowBlurshadowColorshadowOffsetXshadowOffsetYstrokeStyletextAligntextBaselinewidth
canvas基础方法
方法方法方法arc()arcTo()addColorStop()beginPath()bezierCurveTo()clearRect()clip()close()closePath()createImageData()createLinearGradient()createPattern()createRadialGradient()drawFocusIfNeeded()drawImage()ellipse()fill()fillRect()fillText()getImageData()getLineDash()isPointInPath()isPointInStroke()lineTo()measureText()moveTo()putImageData()quadraticCurveTo()rect()restore()rotate()save()scale()setLineDash()setTransform()stroke()strokeRect()strokeText()transform()translate()