收藏
回答

canvas中绘制图片遇到如下错误?

const ctx = canvas.getContext("2d")

// var image = new Image()

// image = new Image()

// image.src = this.data.background_res

// image.onload = function() {

// Promise.all([

// createImageBitmap(this, 10, 10, 100, 100),

// ]).then(function(sprites) {

// ctx.drawImage(sprites[0], 50, 50,sprites[0].width,sprites[0].height);

// });

// }

ctx.drawImage(this.data.background_res,0,0)

报如下错误。我要将本地的图片 座位 canvas的背景。


Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)';at SelectorQuery callback function

TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'

    at CanvasRenderingContext2D.e.drawImage (http://127.0.0.1:51269/appservice/__dev__/WAService.js:2:665214)

    at Se.drawStorage (http://127.0.0.1:51269/appservice/pages/component/storage/storage.js:202:11)

    at n.<anonymous> (http://127.0.0.1:51269/appservice/pages/component/storage/storage.js:165:16)

    at Function.<anonymous> (http://127.0.0.1:51269/appservice/__dev__/WAService.js:2:1246304)

    at http://127.0.0.1:51269/appservice/__dev__/WAService.js:2:127441

    at http://127.0.0.1:51269/appservice/__dev__/WAService.js:2:1246423

    at Array.forEach (<anonymous>)

    at http://127.0.0.1:51269/appservice/__dev__/WAService.js:2:1246396

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签