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


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

fromSource()方法用於以數組表示形式返回指定顏色的新顏色對象,該顏色表示為RGBA(紅綠藍和Alpha)格式。

用法:

fromSource( source )

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

  • source:此參數以RGBA格式保存指定的值數組。

返回值:此方法以“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 fromSource() function 
        // over the array of specified color 
        // value in RGBA format 
        console.log(fabric.Color 
            .fromSource([200, 100, 100, 0.5])); 
    </script> 
</body> 
  
</html>

輸出:

{"_source":[200,100,100,0.5]}

範例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 arrays of  
        // color values in RGBA format 
        var Black = [0, 0, 0, 1.0]; 
        var Blue = [0, 0, 255, 0.5]; 
        var Yellow = [255, 255, 0.9]; 
  
        // Calling the fromSource() function over 
        // the above array of specified color values 
        console.log(fabric.Color.fromSource(Black)); 
        console.log(fabric.Color.fromSource(Blue)); 
        console.log(fabric.Color.fromSource(Yellow)); 
    </script> 
</body> 
  
</html>

輸出:

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

相關用法


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