HTMLキャンバスglobalCompositeOperationプロパティ
例
四角形を描画するために異なる値を使用してGlobalCompositeOperation。 赤い四角形がターゲット画像である、青い矩形は 、ソースイメージです。
ソースオーバー
先オーバー
JavaScriptを:
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);
»をお試しください
ブラウザのサポート
Internet Explorer 9の、Firefoxの、オペラ、ChromeとSafariのサポートglobalCompositeOperationプロパティ。
注:のInternet Explorer 8およびそれ以前のバージョンでは、<キャンバス>要素をサポートしていません。
定義と使用法
globalCompositeOperationプロパティセットまたはソース(新しい)イメージが画像上のターゲット(既存)にレンダリングされる方法を返します。
あなたが描画キャンバスを配置する予定=ソースイメージ 。
ターゲット=あなたは、描画キャンバス上に配置されたイメージを持っています。
デフォルト: | ソースオーバー |
---|---|
JavaScriptシンタックス: | コンテキスト.globalCompositeOperation = "ソースで"; |
プロパティ値
值 | 描述 |
---|---|
source-over | 默认。在目标图像上显示源图像 。 |
source-atop | 在目标图像顶部显示源图像 。 源图像位于目标图像之外的部分是不可见的。 |
source-in | 在目标图像中显示源图像 。只有目标图像之内的源图像部分会显示, 目标图像是透明的。 |
source-out | 在目标图像之外显示源图像 。只有目标图像之外的源图像部分会显示, 目标图像是透明的。 |
destination-over | 在源图像上显示目标图像 。 |
destination-atop | 在源图像顶部显示目标图像 。 目标图像位于源图像之外的部分是不可见的。 |
destination-in | 在源图像中显示目标图像 。只有源图像之内的目标图像部分会被显示, 源图像是透明的。 |
destination-out | 在源图像之外显示目标图像 。只有源图像之外的目标图像部分会被显示, 源图像是透明的。 |
lighter | 显示源图像 + 目标图像 。 |
copy | 显示源图像 。忽略目标图像 。 |
xor | 使用异或操作对源图像与目标图像进行组合。 |
HTMLキャンバスリファレンスマニュアル