获取到像素点,遇到255红色rgb的改为黑色0
ps:红色的rgb为255 0 0
function test(base64) {
// 创建一个Canvas元素
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
var redStamp = new Image();
redStamp.src = base64
redStamp.onload = function () {
canvas.width = redStamp.width;
canvas.height = redStamp.height;
context.drawImage(redStamp, 0, 0);
var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
var data = imageData.data;
for (var i = 0; i < data.length; i += 4) {
if (data[i] === 255) {
data[i] = 0;
data[i + 1] = 0;
data[i + 2] = 0;
}
}
context.putImageData(imageData, 0, 0);
var base64 = canvas.toDataURL();
console.log(base64);
};
}