lwip icon indicating copy to clipboard operation
lwip copied to clipboard

Set pixel inside a loop

Open mvrk21 opened this issue 8 years ago • 1 comments

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 ?

mvrk21 avatar Dec 19 '16 20:12 mvrk21

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); }); }

zynydfcdhj avatar Apr 09 '18 12:04 zynydfcdhj