Fabric.js toBlackWhite() 方法

Fabric.js toBlackWhite() 方法

toBlackWhite() 方法用于将指定颜色表示的任何类型转换为其黑白表示。

语法:

toBlackWhite(threshold)

参数: 该方法接受一个上述提及并如下所述的参数:

  • threshold: 该参数保存指定的阈值。

返回值: 该方法返回其黑白表示中的颜色表示。

示例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 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:

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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程