Open mvrk21 opened 7 years ago
lwip.create(800,533,function(err, newimage){ batch = newimage.batch(); lwip.open('./wmimg/src.jpg', function(err, src){ lwip.open('./wmimg/mask.png', function(err, mask){ for (var x = 0; x < 800; x++){ for (var y = 0; y < 533; y++){ //if (x==402 && y==469){ var srcRGB = src.getPixel(x, y); var maskRGB = mask.getPixel(x, y); var r = qufan(srcRGB.r,maskRGB.r,maskRGB.a); var g = qufan(srcRGB.g,maskRGB.g,maskRGB.a); var b = qufan(srcRGB.b,maskRGB.b,maskRGB.a); var rgb = {}; rgb.r = r; rgb.g = g; rgb.b = b;
batch.setPixel(x, y, rgb);
if (x==799 && y==532){
jumptodo(batch);
}
//newimage.setPixel(x, y, color, callback)
//console.log(r,b)
//}
}
}
}); });
}) function jumptodo(batch){ console.log('ok'); batch.writeFile('./wmimg/new.jpg', function(err){ if (err) console.log(err); }); }
I am trying to change the pixel values when a condition is true. I have tried using the getPixel to get the rgba values of all pixels. Now how do I set the pixels back. As setPixel has a callback function and using it inside a loop didn't work for me. Can anyone help me here ?