1e41f4b71Sopenharmony_ci# Image 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe **Image** object is an image on the canvas. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## Attributes 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci| Name | Type | Default Value | Mandatory | Description | 13e41f4b71Sopenharmony_ci| ------- | -------------- | ---- | ---- | ----------------- | 14e41f4b71Sopenharmony_ci| src | string | - | Yes | Image resource path. | 15e41f4b71Sopenharmony_ci| width | <length> | 0px | No | Image width. | 16e41f4b71Sopenharmony_ci| height | <length> | 0px | No | Image height. | 17e41f4b71Sopenharmony_ci| onload | Function | - | No | Function called when an image is successfully loaded. This function has no parameter.| 18e41f4b71Sopenharmony_ci| onerror | Function | - | No | Function called when an image fails to be loaded. This function has no parameter.| 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## Example 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci```html 24e41f4b71Sopenharmony_ci<!-- xxx.hml --> 25e41f4b71Sopenharmony_ci<div> 26e41f4b71Sopenharmony_ci <canvas ref="canvas" style="width: 500px; height: 500px; "></canvas> 27e41f4b71Sopenharmony_ci</div> 28e41f4b71Sopenharmony_ci``` 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci```js 31e41f4b71Sopenharmony_ci// xxx.js 32e41f4b71Sopenharmony_ciexport default { 33e41f4b71Sopenharmony_ci onShow() { 34e41f4b71Sopenharmony_ci const el = this.$refs.canvas; 35e41f4b71Sopenharmony_ci var ctx = el.getContext('2d'); 36e41f4b71Sopenharmony_ci var img = new Image(); 37e41f4b71Sopenharmony_ci // It is recommended that the image be stored in the common directory. 38e41f4b71Sopenharmony_ci img.src = 'common/images/example.jpg'; 39e41f4b71Sopenharmony_ci img.onload = function () { 40e41f4b71Sopenharmony_ci console.log('Image load success'); 41e41f4b71Sopenharmony_ci ctx.drawImage(img, 0, 0, 360, 250); 42e41f4b71Sopenharmony_ci }; 43e41f4b71Sopenharmony_ci img.onerror = function () { 44e41f4b71Sopenharmony_ci console.log('Image load fail'); 45e41f4b71Sopenharmony_ci }; 46e41f4b71Sopenharmony_ci } 47e41f4b71Sopenharmony_ci} 48e41f4b71Sopenharmony_ci``` 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci 52