Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Canvas js中用图像替换形状?_Javascript_Image_Canvas_Litterallycanvas.js - Fatal编程技术网

Javascript 如何在Canvas js中用图像替换形状?

Javascript 如何在Canvas js中用图像替换形状?,javascript,image,canvas,litterallycanvas.js,Javascript,Image,Canvas,Litterallycanvas.js,我正在尝试用一个图像文件替换下面的椭圆形状 /* this is the image variable I'm trying to use to replace the shape*/ var img = new Image(); img.addEventListener('load', function(e) { canvas.drawImage(this, 0, 0, 400, 400); }, true); img.src="img/crystal.png"; /* this i

我正在尝试用一个图像文件替换下面的椭圆形状

/* this is the image variable I'm trying to use to replace the shape*/
var img = new Image();
img.addEventListener('load', function(e) {
    canvas.drawImage(this, 0, 0, 400, 400);
}, true);
img.src="img/crystal.png";

/* this is circle shape I'm trying to replace*/

    stroke(0);
    fill(175);
    ellipse(xpos, ypos, 32, 32);
}

如果其他方法都不起作用,您可以尝试使用此方法。您的问题有点不清楚,您可以发布更多的代码吗?我不知道litterallycanvas.js,但是
stroke()
fill()
eliple()
是全局方法吗?你这样称呼他们吗?你想让你的图像填充椭圆形状,还是仅仅在与实际椭圆相同的位置?