Fabric.js fromRgba()方法

Fabric.js fromRgba()方法

fromRgba()方法用于返回RGBA(红绿蓝和透明度)格式中指定颜色的新色彩对象。

语法:

fromRgba(color)

参数: 此方法接受一个上述并且下面描述的参数:

  • color: 此参数保存RGBA格式的指定字符串颜色值。

返回值: 此方法将返回一个以“RGBA(红-绿-蓝-透明度)”格式表示的指定颜色的新颜色对象。

示例1:

<!DOCTYPE html> 
<html> 
  
<head> 
    <!-- Adding the FabricJS library --> 
    <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"> 
    </script> 
</head> 
  
<body> 
    <script type="text/javascript"> 
  
        // Calling the fromRgba() function over the 
        // above specified color value in RGBA format 
        console.log(fabric.Color.fromRgba("rgb(0, 0, 128, 0.4)")); 
    </script> 
</body> 
  
</html> 

输出:

{"_source":[0,0,128,0.4]}

示例2:

<!DOCTYPE html> 
<html> 
  
<head> 
    <!-- Adding the FabricJS library --> 
    <script src= 
"https://cdnjs.cloudflare.com/ajax/libs/fabric.js/3.6.2/fabric.min.js"> 
    </script> 
</head> 
  
<body> 
    <script type="text/javascript"> 
  
        // Initializing some color values 
        // in RGBA format 
        var Black = "rgba(0, 0, 0, 1.0)"; 
        var Blue = "rgba(0, 0, 255, 0.5)"; 
        var Yellow = "rgba(255, 255, 0.9)"; 
  
        // Calling the fromRgba() function over 
        // the above specified color values 
        console.log(fabric.Color.fromRgba(Black)); 
        console.log(fabric.Color.fromRgba(Blue)); 
        console.log(fabric.Color.fromRgba(Yellow)); 
    </script> 
</body> 
  
</html> 

输出:

{"_source":[0,0,0,1]}
{"_source":[0,0,255,0.5]}
{"_source":[255,255,0,1]}

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程