星空网 > 软件开发 > 网页设计

html5 canvas画布上合成

source-over默认。在目标图像上显示源图像。
source-atop在目标图像顶部显示源图像。源图像位于目标图像之外的部分是不可见的。
source-in在目标图像中显示源图像。只有目标图像内的源图像部分会显示,目标图像是透明的。
source-out在目标图像之外显示源图像。只会显示目标图像之外源图像部分,目标图像是透明的。
destination-over在源图像上方显示目标图像。
destination-atop在源图像顶部显示目标图像。源图像之外的目标图像部分不会被显示。
destination-in在源图像中显示目标图像。只有源图像内的目标图像部分会被显示,源图像是透明的。
destination-out在源图像外显示目标图像。只有源图像外的目标图像部分会被显示,源图像是透明的。
lighter显示源图像 + 目标图像。
copy显示源图像。忽略目标图像。
source-over使用异或操作对源图像与目标图像进行组合。

以上是HTML 5 canvas globalCompositeOperation 属性

<!DOCTYPE html><html><body><canvas id="myCanvas" width="300" height="150" >Your browser does not support the HTML5 canvas tag.</canvas><script>var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.fill;ctx.fillRect(20,20,75,50);ctx.fill;	ctx.globalCompositeOperation="source-over";ctx.fillRect(50,50,75,50);	ctx.fill;ctx.fillRect(150,20,75,50);ctx.fill;	ctx.globalCompositeOperation="destination-over";ctx.fillRect(180,50,75,50);	</script></body></html>

 

HTML 5 canvas globalAlpha 属性    globalAlpha=0-1;

<!DOCTYPE html><html><body><canvas id="myCanvas" width="300" height="150" >Your browser does not support the HTML5 canvas tag.</canvas><script>var c=document.getElementById("myCanvas");var ctx=c.getContext("2d");ctx.fill;ctx.fillRect(20,20,75,50);//Turn transparency onctx.globalAlpha=0.2;ctx.fill; ctx.fillRect(50,50,75,50); ctx.fill; ctx.fillRect(80,80,75,50);</script></body></html>

 以上2段为W3SCHOOL上的说明:昨天我写到了,API经过国外翻译之后可能翻译的结果让人感觉无语 所以多实践 才能提高

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html ="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>canvas合成</title><script src='/images/loading.gif' data-original="js/modernizr.js"></script></head><body><script type="text/javascript">window.addEventListener('load',eventWindowLoaded,false);function eventWindowLoaded(){  canvasApp();}function canvasSupport(){  return Modernizr.canvas;}function canvasApp(){  if(!canvasSupport()){    return;  }else{    var theCanvas = document.getElementById('canvas')    var context = theCanvas.getContext("2d")  }  drawScreen();  function drawScreen(){    //在屏幕上绘制一个大方块    context.fillStyle = "black";    context.fillRect(10,10,200,200);    //保留globalCompositeOperation原有值不变    //现在绘制一个红色正方形        context.fillStyle = "#ff0000";    context.fillRect(1,1,50,50);        //现在设置为source-over    context.globalCompositeOperation = "source-over";    context.fillRect(60,1,50,50);    //现在设置为destination-over    context.globalCompositeOperation = "destination-over";    context.fillRect(1,60,50,50);    //现在设置globalAlpha    context.globalAlpha = .5;    //现在设置source-atop    context.globalCompositeOperation = "source-atop";    context.fillRect(60,60,50,50);           }  }</script><canvas id="canvas" width="500" height="500">你的浏览器无法使用canvas如有疑问加QQ:1035417613;小白童鞋;你的支持是我最大的快乐!!</canvas></body></html>

 




原标题:html5 canvas画布上合成

关键词:HTML

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流