简体中文
image对象, 用于 canvas 绘制
| 名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
|---|---|---|---|---|---|
| src | string.ImageURIString | 是 | - | 图片url |
| Web | 微信小程序 | Android | iOS | HarmonyOS | HarmonyOS uni-app x UTS 插件 |
|---|---|---|---|---|---|
| 4.0 | x | 4.25 | 4.25 | 4.61 | 4.61 |
提示
鸿蒙平台、微信小程序不支持 new Image() 方式创建,需要通过跨平台写法 CanvasContext.createImage(), 示例如下:
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);
}
}
})