Fabric.js fromRgb()方法

Fabric.js fromRgb()方法

fromRgb()方法 用于返回指定的RGB格式(红色、绿色和蓝色)的颜色对象。

语法:

fromRgb(color)

参数: 此方法接受一个以上述方式提到并以下述方式描述的参数:

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

返回值: 此方法返回以RGB格式中指定颜色的“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 fromRgb() function over 
   // the specified color value in RGB format 
   console.log(fabric.Color.fromRgb("rgb(255, 0, 0)"));  
   console.log(fabric.Color.fromRgb("rgb(10, 14, 20)"));  
  </script> 
  
</body> 
  
</html>

输出:

{"_source":[255,0,0,1]}
{"_source":[10,14,20,1]}

示例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 RGB format 
   var Lime = "rgb(255, 0, 0)"; 
   var Blue = "rgb(0, 0, 255)"; 
   var Yellow = "rgb(255, 255, 0)"; 
  
   // Calling the fromRgb() function over 
   // the above specified color values 
   console.log(fabric.Color.fromRgb(Lime));  
   console.log(fabric.Color.fromRgb(Blue));  
   console.log(fabric.Color.fromRgb(Yellow));  
  </script> 
  
</body> 
  
</html>

输出:

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程