canvas 图像合成

globalAlpha

globalAlpha 属性设置或返回绘图的当前透明值(alpha 或 transparency)。

globalAlpha 属性值必须是介于 0.0(完全透明) 与 1.0(不透明) 之间的数字。

语法:context.globalAlpha=number;

number介于0到1之间,0 完全透明,1 不透明

globalCompositeOperation

globalCompositeOperation 属性设置或返回如何将一个源(新的)图像绘制到目标(已有)的图像上(即所绘制的两个图像重叠式怎么处理)。

源图像 = 您打算放置到画布上的绘图。

目标图像 = 您已经放置在画布上的绘图。

语法:context.globalCompositeOperation="source-in";

参数说明:


<span style="font-family:Comic Sans MS;"><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="script/jquery-2.1.0.js"></script>
    <script type="text/javascript">
        $(function () {


            var canvas = document.getElementById("sourceover");
            var context = canvas.getContext("2d");
           
            context.save();
            context.fillStyle = "blue";
            context.globalAlpha = 0.7;
            context.fillRect(0, 0, 100, 100);
            context.globalCompositeOperation = "source-atop";
            context.fillStyle = "red";
            context.fillRect(40, 40, 100, 100);
            context.restore();

            context.save();
            context.fillStyle = "blue";
            context.fillRect(150, 0, 100, 100);
            context.globalCompositeOperation = "source-over";
            context.fillStyle = "red";
            context.fillRect(190, 40, 100, 100);
            context.restore();
        });
    </script>
</head>
<body>
    <canvas id="sourceover" width="600" height="600" style="border:1px solid blue;" ></canvas>
</body>
</html>
</span>





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值