I want to insert this image
var img=new Image();
img.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/desert1.jpg";
Into the circle, that I'm drawing with this function
function drawBall() {
//ctx.globalCompositeOperation='destination-in';
ctx.beginPath();
ctx.arc(x, y, ballRadius, 0, Math.PI*2);
ctx.drawImage(img,10,20);
ctx.globalCompositeOperation='source-over';
ctx.fillStyle = "#0095DD";
ctx.fill();
ctx.closePath();
}
Here's what the canvas currently looks like:
globalCompositeOperation mode
source-over
is the default gCO mode, which draws new content over the existing one.You need to set it to
destination-in
after you've drawn something on the canvas, so only the pixels where both the new pixels and the already painted ones will overlap, stay.