algorithm - How to draw only the visible pixels which are >0% alpha with a custom color in canvas? -
algorithm - How to draw only the visible pixels which are >0% alpha with a custom color in canvas? -
i create performance nail test png images , other shapes. don't care shapes because technique there no performance issues @ checking (not setup).
i intent collect images on screen in secondary canvas nail test. each image drawn create new color attached particular image. draw of them in canvas, each image have different fill color.
when click on pixel (x, y) color (r, g, b). every color mapped image, image clicked no error (i don't waste finding nail click).
i know limited 256*256*256=16 777 216 items because colors don't think problem now...
so need know how set fill colors on secondary canvas based on visible pixels each image.
update
can see right it's nail test map. if click on black shade (c) instantly know i've clicked on bluish box without other calculation.
one improvement cache alpha data. reuse same alpha info each image instance (we must take care scaling , rotation...).
thanks
here’s how color-mask non-transparent pixels of canvas image.
be sure replace "putyourimagehere.png" own image url.
<!doctype html> <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <style> body{ background-color: ivory; } canvas{border:1px solid blue;} </style> <script> $(function(){ var img=new image(); img.onload=function(){ var red=255; var blue=0; var green=0; var canvascopy=document.getelementbyid("canvascopy"); var ctxcopy=canvascopy.getcontext("2d"); var c=document.getelementbyid("canvas"); var ctx=c.getcontext("2d"); ctx.drawimage(this,0,0); var imgdata=ctx.getimagedata(0,0,c.width,c.height); (var i=0;i<imgdata.data.length;i+=4) { if(imgdata.data[i+3]>0){ imgdata.data[i]=red; imgdata.data[i+1]=green; imgdata.data[i+2]=blue; imgdata.data[i+3]=255; } } ctxcopy.putimagedata(imgdata,0,0); } img.src = "putyourimagehere.png"; }); // end $(function(){}); </script> </head> <body> <canvas id="canvas" width="300" height="300"></canvas> <canvas id="canvascopy" width="300" height="300"></canvas> </body> </html>
algorithm canvas hit
Comments
Post a Comment