canvas常用的几种重叠绘图设置globalCompositeOperation

编程入门 行业动态 更新时间:2024-10-24 18:24:21

canvas常用的<a href=https://www.elefans.com/category/jswz/34/1769370.html style=几种重叠绘图设置globalCompositeOperation"/>

canvas常用的几种重叠绘图设置globalCompositeOperation

globalCompositeOperation描述了2个图形交叉的时候是什么样子,它的值有很多,这里就盗一张很经典的图:

我们来看一个source-in的例子吧: 

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Document</title></head><body><div>合成图层:只展示哪部分内容,是交际还是补</div><canvas id="myCanvas" width="600" height="600"></canvas><script>// 获取画布var canvas = document.getElementById('myCanvas')// 获取画布的上下文var ctx = canvas.getContext('2d')// 绘制矩形ctx.fillStyle = 'red'ctx.fillRect(100, 100, 200, 200)// 设置只绘制交际部分ctx.globalCompositeOperation = 'source-in'// 绘制矩形ctx.fillStyle = 'blue'ctx.fillRect(200, 200, 200, 200)</script></body>
</html>

如果没有source-in显示的效果: 

设置了source-in的效果: 

更多推荐

canvas常用的几种重叠绘图设置globalCompositeOperation

本文发布于:2023-12-05 06:11:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1663333.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几种   常用   canvas   globalCompositeOperation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!