HTML 캔버스 globalCompositeOperation 속성
예
사각형을 그리려면 다른 값을 사용하여 GlobalCompositeOperation. 붉은 사각형대상 이미지의청색 사각형이소스 이미지이다 :
소스 오버
대상 오버
자바 스크립트 :
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(20,20,75,50);
ctx.globalCompositeOperation="source-over";
ctx.fillStyle="blue";
ctx.fillRect(50,50,75,50);
ctx.fillStyle="red";
ctx.fillRect(150,20,75,50);
ctx.globalCompositeOperation="destination-over";
ctx.fillStyle="blue";
ctx.fillRect(180,50,75,50);
var ctx=c.getContext("2d");
ctx.fillStyle="red";
ctx.fillRect(20,20,75,50);
ctx.globalCompositeOperation="source-over";
ctx.fillStyle="blue";
ctx.fillRect(50,50,75,50);
ctx.fillStyle="red";
ctx.fillRect(150,20,75,50);
ctx.globalCompositeOperation="destination-over";
ctx.fillStyle="blue";
ctx.fillRect(180,50,75,50);
»시도
브라우저 지원
인터넷 익스플로러 9, 파이어 폭스, 오페라, 크롬과 사파리 지원 globalCompositeOperation 속성입니다.
참고 : 인터넷 익스플로러 8 이전 버전의 <캔버스> 요소를 지원하지 않습니다.
정의 및 사용
globalCompositeOperation 속성 세트 또는 소스 (신규) 이미지가 이미지의 대상 (기존)에 렌더링하는 방법으로 돌아갑니다.
= 원본 이미지가 도면 캔버스를 배치 할 계획입니다.
대상 = 당신은 그리기 캔버스에 배치 이미지를 가지고있다.
기본값 : | 소스 오버 |
---|---|
자바 스크립트 구문 : | 문맥 .globalCompositeOperation = "소스에서"; |
속성 값
值 | 描述 |
---|---|
source-over | 默认。在目标图像上显示源图像 。 |
source-atop | 在目标图像顶部显示源图像 。 源图像位于目标图像之外的部分是不可见的。 |
source-in | 在目标图像中显示源图像 。只有目标图像之内的源图像部分会显示, 目标图像是透明的。 |
source-out | 在目标图像之外显示源图像 。只有目标图像之外的源图像部分会显示, 目标图像是透明的。 |
destination-over | 在源图像上显示目标图像 。 |
destination-atop | 在源图像顶部显示目标图像 。 目标图像位于源图像之外的部分是不可见的。 |
destination-in | 在源图像中显示目标图像 。只有源图像之内的目标图像部分会被显示, 源图像是透明的。 |
destination-out | 在源图像之外显示目标图像 。只有源图像之外的目标图像部分会被显示, 源图像是透明的。 |
lighter | 显示源图像 + 目标图像 。 |
copy | 显示源图像 。忽略目标图像 。 |
xor | 使用异或操作对源图像与目标图像进行组合。 |
HTML 캔버스 참조 설명서