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
})