zoukankan      html  css  js  c++  java
  • canvas图形组合

    代码:

     1 /**
     2  * Created by Administrator on 2016/1/27.
     3  */
     4 function draw (id){
     5     var canvas = document.getElementById(id);
     6     var context = canvas.getContext('2d');
     7     context.globalCompositeOperation = "lighter";
     8     RectArc(context);
     9 }
    10 function RectArc(context){
    11 //    context.fillStyle = "#DA70D6"
    12 //    context.fillRect(0,0,400,400);
    13     context.beginPath();
    14     context.rect(10,10,50,50);
    15     context.fillStyle = "#FF6347";
    16     context.fill();
    17     context.beginPath();
    18     context.arc(60,60,30,0,Math.PI*2,true);
    19     context.fillStyle = "#00FF7F";
    20     context.fill();
    21 }
    View Code

    图形组合主要用到 globalCompositeOperation方法。

    其格式: 

        context.globalCompositeOperation = "值";

        值表:

          

    为方便记忆自己总结如下(以下的图片演示解释,方块为源图像,圆形为目标图像):

      分组记忆:

       1)copy:只保留新图形。

       2)darker和lighter:

           darker:重叠部分颜色由两个颜色值相减决定;

           lighter:重叠部分颜色由两个颜色值相加决定;

                                 

       3)destination和source:

          destination决定源图像在目标图像的哪;

          source决定目标图像在源图像的哪。

          另有-in  -out  -atop -over等后缀。

          in:目标图像在源(目标)图像的里面会显示,其他透明。

          out:目标(源)图像在源(目标)图像的外面会显示,其他透明。

          atop:在顶部显示。只是简单的覆盖。

          over:在上方显示。显示覆盖的,其他的透明。

          

        4)xor:重叠部分透明。

              

    myGitgub https://github.com/mfx55 希望我的博客能帮到你
  • 相关阅读:
    禁止IOS双击上滑
    keychains
    GUID 格式化
    Dart基础使用手册
    关于Android 8.0java.lang.SecurityException: Permission Denial错误的解决方法
    Android开发者的Anko使用指南(四)之Layouts
    Android开发者的Anko使用指南(三)之资源
    Android开发者的Anko使用指南(二)之Dialogs
    Android开发者的Anko使用指南(一)之Intent
    hornor8改user模式为debug模式
  • 原文地址:https://www.cnblogs.com/chenluomenggongzi/p/5163769.html
Copyright © 2011-2022 走看看