1***@qq.com
1***@qq.com
  • 发布:2024-03-25 18:27
  • 更新:2024-03-26 11:41
  • 阅读:164

canvasGetImageData 调用不成功

分类:uni-app
<template> <view class="picker-color" style="{width: (props.radius + props.thumkRadius) 2 + 'rpx', height: (props.radius + props.thumkRadius) 2 + 'rpx'}"> <canvas class="disk" :id="diskId" :canvas-id="diskId" style="{width: props.radius 2 + 'rpx', height: props.radius 2 + 'rpx'}" @touchstart="handleOnColorClick"></canvas>
<canvas class="thumk" :id="thumkId" :canvas-id="thumkId"

style="{width: props.thumkRadius 2 + 'rpx', height: props.thumkRadius 2 + 'rpx', left: thumkPos.x + 'px', top: thumkPos.y + 'px'}"></canvas> </view>
</template>

const handleGetImgData = (canvasId : string, x : number, y : number) => {
return new Promise<void>((resolve) => {
uni.canvasGetImageData({
canvasId,
x,
y,
width: diskRect.width,
height: diskRect.height,
success: (data) => {
console.log(data);
resolve()
}, complete(err) {
console.log(err);
}
})
})
}

我在canvas初始化成功后 通过canvasGetImageData获取某个像素点的颜色
报错 {errMsg: "canvasGetImageData:fail IndexSizeError: Failed to …CanvasRenderingContext2D': The source width is 0."}
App.vue:11 App Hide

2024-03-25 18:27 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者) - MwM-Mai

找到原因了, x和y属性必须是0, 不然就会报错

要回复问题请先登录注册