<canvas type="webgl" id="webgl" canvas-id='webgls' style="width: 370px; height: 370px;margin: auto;"
@touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" />
touchMove(e) {
const {
x,
y
} = e.changedTouches[0]
wx.canvasGetImageData({
canvasId: 'webgls',
x,
y,
width: 1,
height: 1,
success: (res) => {
uni.showToast({
title: 'success'
})
var pixel = res.data;
var r = pixel[0];
var g = pixel[1];
var b = pixel[2];
var a = pixel[3] / 255;
var rHex = r.toString(16);
r < 16 && (rHex = "0" + rHex);
var gHex = g.toString(16);
g < 16 && (gHex = "0" + gHex);
var bHex = b.toString(16);
b < 16 && (bHex = "0" + bHex);
var hexColor = "#" + rHex + gHex + bHex;
console.info(hexColor)
},
fail: (error) => {
console.info(error)
},
complete: () => {
this.platform.dispatchTouchEvent(e);
}
}, this)
}
你提供一下回调报错.,请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
<template>
<view style="">
<canvas type="webgl" id="webgl" canvas-id='webgls' style="width: 300px; height: 300px;margin: auto;"
@touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" />
</view>
</template>
<script>
export default {
//获取画布
touchMove(e) {
this.platform.dispatchTouchEvent(e);
const {
x,
y
} = e.changedTouches[0]
wx.canvasGetImageData({
canvasId: 'webgls',
x,
y,
width: 1,
height: 1,
success: (res) => {
uni.showToast({
title: 'success'
})
var pixel = res.data;
var r = pixel[0];
var g = pixel[1];
var b = pixel[2];
var a = pixel[3] / 255;
var rHex = r.toString(16);
r < 16 && (rHex = "0" + rHex);
var gHex = g.toString(16);
g < 16 && (gHex = "0" + gHex);
var bHex = b.toString(16);
b < 16 && (bHex = "0" + bHex);
var hexColor = "#" + rHex + gHex + bHex;
console.info(hexColor)
},
fail: (error) => {
console.info(error)
},
complete: () => {
this.platform.dispatchTouchEvent(e);
}
}, this)
},
},
}
</script>