canvas中globalCompositeOperation属性值所代表的的值表达含义及样式

CANVAS属性记录
 一:globalCompositeOperation的属性
CanvasRenderingContext2D.globalCompositeOperation Canvas 2D API的 属性设置在绘制新形状时要应用的合成操作的类型。
1.1 Type类型
在这里插入图片描述

1.2 source-over
这是默认设置,并在现有画布内容的顶部绘制新形状
在这里插入图片描述

1.3 source-in
新图形仅在新图形和目标画布重叠的位置绘制。其他一切都是透明的。
在这里插入图片描述

	const canvas = this.$refs.canvas
    const ctx = canvas.getContext('2d');
    // xor:重叠部分空  lighter:重叠部分颜色是重组颜色 
    // destination-atop:切割颜色
    

    ctx.fillStyle = 'blue';
    ctx.fillRect(10, 10, 100, 100);
    ctx.globalCompositeOperation = 'source-in';
    ctx.fillStyle = 'red';
    ctx.fillRect(50, 50, 100, 100);
 

12.1 Source-out
新形状在不与现有画布内容重叠的位置绘制。
在这里插入图片描述

	ctx.fillStyle = 'blue';
    ctx.fillRect(10, 10, 100, 100);
	ctx.globalCompositeOperation = 'source-out';
    ctx.fillStyle = 'red';
    ctx.fillRect(50, 50, 100, 100);

17.1 source-atop
新形状仅在与现有画布内容重叠的位置绘制。
在这里插入图片描述

	ctx.fillStyle = 'blue';
    ctx.fillRect(10, 10, 100, 100);
     ctx.globalCompositeOperation = 'source-atop';
     ctx.fillStyle = 'red';
     ctx.fillRect(50, 50, 100, 100);

22.1 destination-over
在现有画布内容后面绘制新形状。
在这里插入图片描述

22.2 destination-in
现有画布内容保留在新形状和现有画布内容重叠的位置。其他一切都是透明的
在这里插入图片描述

ctx.fillStyle = 'blue';
ctx.fillRect(10, 10, 100, 100);
 ctx.globalCompositeOperation = 'destination-in';
 ctx.fillStyle = 'red';
 ctx.fillRect(50, 50, 100, 100);

22.3 destination-out
现有内容保留在不与新形状重叠的位置。
在这里插入图片描述

22.4 destination-atop
现有画布仅保留在与新形状重叠的位置。新形状绘制在画布内容的后面
在这里插入图片描述

22.5 lighter
其中两个形状重叠的颜色是通过添加颜色值确定的。
在这里插入图片描述

22.6 copy
只显示新形状。
在这里插入图片描述

22.7 xor
形状是透明的重叠和绘制正常的地方,其他地方。
在这里插入图片描述

22.8 multiply
顶层的像素与底层的对应像素相乘。结果是画面变得更暗。
在这里插入图片描述

22.9 screen
像素被反转、相乘,然后再次反转。结果是一张较浅的图片(与乘法相反)
在这里插入图片描述

22.10 overlay
乘法和屏幕的组合。底层的深色部分变暗,浅色部分变亮。
在这里插入图片描述

22.11 darken
保留两层中最暗的像素。
在这里插入图片描述

22.12 lighten
保留两层中最轻的像素。
在这里插入图片描述

22.13 color-dodge
将底层除以倒置的顶层。
在这里插入图片描述

22.14 color-burn
将反转的底层除以顶层,然后反转结果。
在这里插入图片描述

22.15 hard-light
叠加和屏幕状叠加的组合,但顶层和底层交换。
在这里插入图片描述

22.16 soft-light
柔和的硬光版本。纯黑或白不会导致纯黑或白。
在这里插入图片描述

22.17 difference
从顶层减去底层,或者反过来总是得到一个正值。
在这里插入图片描述

22.18 exclusion
就像是不同,但对比度低。
在这里插入图片描述

22.19 hue
保留底层的亮度和色度,同时采用顶层的色调。
在这里插入图片描述

22.20 saturation
保留底层的亮度和色调,同时采用顶层的色度。
在这里插入图片描述

22.21 color
保留底层的亮度,同时采用顶层的色调和色度。
在这里插入图片描述

22.22 luminosity
在采用顶层的luma时,保持底层的色调和色度。
在这里插入图片描述

参考文章 https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值