<template>
<view class="content">
<canvas id="ec-heatmp-mask" canvas-id="ec-heatmp-mask" style="width: 325px; height: 325px"></canvas>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
mounted() {
this.handleClip('./681755.png')
},
methods: {
handleClip(imgSrc) {
const ctx = uni.createCanvasContext('ec-heatmp-mask', this)
if (ctx) {
ctx.drawImage('./681755.png', 0, 0, 325, 325)
uni.canvasGetImageData({
canvasId: 'ec-heatmp-mask',
x: 0,
y: 0,
width: 325,
height: 325,
success(res) {
let imageData = res
const pixels = res.data
console.log(pixels);
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
}
}
uni.canvasPutImageData({
canvasId: 'ec-heatmp-mask',
x: 0,
y: 0,
width: 1,
data: pixels,
success(res) {
console.log(res);
}
})
}
})
}
}
}
}
</script>
<style>
ec-heatmp-mask {
/* background-color: red; */
}
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>