Fabric.js fromSource()方法
fromSource()方法用于返回一个指定颜色的新颜色对象,以RGBA(红绿蓝和透明度)格式的数组表示。
语法:
fromSource( source )
参数: 此方法接受一个参数,如上所述,并在下面进行描述:
- source: 此参数保存以RGBA格式指定的值数组。
返回值: 此方法返回一个新的颜色对象,格式为“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 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:
<!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]}