Fabric.js 是一個用於處理畫布的 JavaScript 庫。畫布圖像是用於創建圖像實例的 fabric.js 類之一。畫布圖像意味著圖像是可移動的,可以根據需要進行拉伸。 stroke 屬性用於設置畫布圖像的筆觸
方法:首先導入fabric.js庫。導入庫後,在 body 標簽中創建一個包含圖像的畫布塊。之後,初始化一個 Canvas 實例和 Fabric.JS 提供的圖像類,並使用 stroke 屬性設置畫布圖像的筆觸。在此之後在畫布上渲染圖像。
用法:
fabric.Image(image, { stroke:string });
參數:該函數采用上述和以下描述的單個參數:
- stroke:此參數采用字符串值來設置畫布圖像的筆劃。
示例:本示例使用 FabricJS 設置畫布圖像的筆觸屬性,如下例所示:
HTML
<!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>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<b>
Fabric.js | Image stroke Property
</b>
<canvas id="canvas" width="400" height="300"
style="border:2px solid #000000">
</canvas>
<img src=
"https://media.geeksforgeeks.org/wp-content/uploads/20200327230544/g4gicon.png"
width="100" height="100" id="my-image"
style="display:none;">
<br>
<script>
// Creating the instance of canvas object
var canvas = new fabric.Canvas("canvas");
// Getting the image
var img = document.getElementById('my-image');
// Creating the image instance
var geeks = new fabric.Image(img, {
stroke:"green",
strokeWidth:3
});
canvas.add(geeks);
canvas.centerObject(geeks);
</script>
</body>
</html>
輸出:
相關用法
- CSS stroke-width用法及代碼示例
- CSS stroke-linecap用法及代碼示例
- CSS stroke-opacity用法及代碼示例
- CSS stroke-dashoffset用法及代碼示例
- CSS stroke-dasharray用法及代碼示例
- CSS stroke-linejoin用法及代碼示例
- CSS stroke-miterlimit用法及代碼示例
- Fabric.js Text stroke屬性用法及代碼示例
- Fabric.js Circle stroke屬性用法及代碼示例
- Fabric.js Rect stroke屬性用法及代碼示例
- Fabric.js Triangle stroke屬性用法及代碼示例
- Fabric.js Ellipse stroke屬性用法及代碼示例
- Fabric.js Polyline stroke屬性用法及代碼示例
- CSS stroke-color屬性用法及代碼示例
- Fabric.js Textbox stroke屬性用法及代碼示例
- Fabric.js Polygon stroke屬性用法及代碼示例
- Fabric.js line stroke屬性用法及代碼示例
- Fabric.js Path stroke屬性用法及代碼示例
- Fabric.js Group stroke屬性用法及代碼示例
- HTML canvas stroke()用法及代碼示例
- p5.js stroke()用法及代碼示例
- Node.js GM stroke()用法及代碼示例
注:本文由純淨天空篩選整理自dheerchanana08大神的英文原創作品 Fabric.js Image stroke Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。