收藏
回答

canvas.createImage()创建的img,加载长图时一直失败?

 const img = canvas.createImage()
  await new Promise((resolve, reject) => {
        img.onload = () => {
          console.log('图片加载成功,尺寸:', img.width, 'x', img.height)
          resolve(null)
        }
        img.onerror = (err) => {
          console.error('图片加载失败:', {
            error: err,
            path: selectPhotoPath,
            imgObject: img
          })
          reject(new Error(`图片加载失败: ${selectPhotoPath}`))
        }


        // 确保路径正确
        if (!selectPhotoPath) {
          reject(new Error('图片路径为空'))
          return
        }


        // 设置图片源
        console.log('设置图片源:', selectPhotoPath)
        img.src = selectPhotoPath
      })
回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 该问答由AI生成
    01-12
    有用
登录 后发表内容