---
name: "Canvas.createPath2D"
mode: "api"
versionRequirements:
  - { name: "Base Library", version: "2.21.8" }
title: "Canvas.createPath2D - 创建 Path2D 对象"
---

## Canvas.createPath2D

> [VERSION] Base Library >= 2.21.8

### Description

Create a Path2D object to define paths

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | `string \| Path2D` | No | Optional initial path; accepts an existing Path2D object or an SVG path string |

### Return Value

Type: `Path2D`

Path2D path object

### Examples

#### Draw shapes with Path2D

```js
const canvas = await this.instance.getCanvasById('myCanvas');
const ctx = canvas.getContext('2d');
const path = canvas.createPath2D();
path.rect(10, 10, 100, 100);
ctx.fill(path);
```
