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