getImageColor() {
setTimeout(() => {
this.loading = false
}, 1500)
const img = new Image();
img.crossOrigin = 'anonymous'; // 添加此行以允许跨域请求
img.src = this.topimg;
console.log(img)
img.onload = () => {
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
// 计算颜色平均值
// const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
// const data = imageData.data;
var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
console.log(data)
let sumRed = 0;
let s
上传图片并用canvas获取颜色平均值
最新推荐文章于 2024-08-17 23:09:20 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)