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

## Canvas.createImage

> [VERSION] Base Library >= 2.21.8

### Description

Create an image object for drawing onto the Canvas

### Parameters

None


### Return Value

Type: `HTMLImageElement`

Image object

### Examples

#### Create an image and draw it onto the Canvas

```js
const canvas = await this.instance.getCanvasById('myCanvas');
const ctx = canvas.getContext('2d');
const image = canvas.createImage();
image.src = 'https://example.com/image.png';
image.onload = () => {
  ctx.drawImage(image, 0, 0);
};
```
