當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Fabric.js fromRgb()用法及代碼示例

fromRgb()方法用於為RGB(紅色,綠色和藍色)格式的指定顏色返回新的顏色對象。

用法:

fromRgb(color)

參數:此方法接受如上所述和以下描述的參數:

  • color:此參數以RGB格式保存指定的字符串顏色值。

返回值:此方法為RGB格式的指定顏色返回“RGBA(Red-Green-Blue-Alpha)”格式的新顏色對象。

範例1:



Javascript

<!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:

Javascript

<!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]}

相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Fabric.js fromRgb() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。