handleClip(imgSrc) {
const ctx = uni.createCanvasContext('ec-heatmp-mask', this)
if (ctx) {
uni.downloadFile({
url: require('./681755.png'),
success: (res) => {
console.log(res)
console.log(res.tempFilePath)
ctx.drawImage(res.tempFilePath, 0, 0, 325, 325)
ctx.draw()
setTimeout(() => {
uni.canvasGetImageData({
canvasId: 'ec-heatmp-mask',
x: 0,
y: 0,
width: 325,
height: 325,
success(res) {
let imageData = res
const pixels = res.data
let result = pixels.filter(item => item !== 0)
console.log(result)
for (let index = 0; index < pixels.length; index +=
4) {
var r = pixels[index]
var g = pixels[index + 1]
var b = pixels[index + 2]
var a = pixels[index + 3]
if (a == 0) {
pixels[index] = 255
pixels[index + 1] = 255
pixels[index + 2] = 255
pixels[index + 3] = 255
} else {
pixels[index] = 0
pixels[index + 1] = 255
pixels[index + 2] = 255
pixels[index + 3] = 0
}
}
setTimeout(() => {
uni.canvasPutImageData({
canvasId: 'ec-heatmp-mask',
x: 0,
y: 0,
width: 1,
data: pixels,
success(res) {
console.log(res);
},
completeres(res) {
console.log(res);
},
})
},0)
}
})
}, 0)
}
})