提交 4f4141f3 编写于 作者: H hdx

feat(image): 增加跨平台示例

上级 4c6eede4
......@@ -12,3 +12,21 @@
<!-- CUSTOMTYPEJSON.Image.example -->
**提示**
微信小程序不支持 `new Image()` 写法来绘制,需要通过跨平台写法 `CanvasContext.drawImage()`, 示例如下:
```js
uni.createCanvasContextAsync({
id: 'canvas',
component: this, // setup模式使用 getCurrentInstance().proxy
success: (context : CanvasContext) => {
const renderingContext = context.getContext('2d')!;
const image = context.createImage();
image.src = "/static/logo.png";
image.onload = () => {
renderingContext.drawImage(image, 0, 0, 100, 100);
}
}
})
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册