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


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

toBlackWhite()方法用於將任何類型的指定顏色表示形式轉換為黑白表示形式。

用法:

toBlackWhite(threshold)

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

  • threshold:此參數保留指定的閾值。

返回值:此方法以黑白表示形式返回顏色表示。

範例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 toBlackWhite() function over  
 // the specified color values 
 console.log(new fabric.Color("hsl(0, 100%, 50%)").toBlackWhite(0)); 
 console.log(new fabric.Color("hsla(10, 40%, 53%, 0.6)").toBlackWhite(1)); 
</script> 
  
</body> 
  
</html>

輸出:

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

範例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 different color format 
 var A = "hex(fff00f)"; 
 var B = "hsl(12, 13%, 25%)"; 
 var C = "hsla(10, 40%, 13%, 0.6)"; 
 var D = "rgb(10, 40, 13)"; 
  
 // Calling the toBlackWhite() function over  
 // the above specified color values 
 console.log(new fabric.Color(A).toBlackWhite()); 
 console.log(new fabric.Color(B).toBlackWhite(0)); 
 console.log(new fabric.Color(C).toBlackWhite(1)); 
 console.log(new fabric.Color(D).toBlackWhite(2)); 
</script> 
  
</body> 
  
</html>

輸出:

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

相關用法


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