<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
1 个回复
1***@qq.com (作者) - MwM-Mai
找到原因了, x和y属性必须是0, 不然就会报错