admin管理员组

文章数量:1419891

I basically want to put a shape that the user "cuts" from the main canvas to a random place in the main canvas. I hold the cut out shape's context and want to use;

ctx.drawImage(gctx,corx,cory);

to put gctx, which holds the context of the cut shape in to ctx, which is the main canvas context. Both are global and already set when they e upon the above code line. Also gctx is set as below;

ghostcanvas = document.createElement('canvas');
ghostcanvas.height = canvas.height;
ghostcanvas.width = canvas.width;
gctx = ghostcanvas.getContext('2d');

From firebug i can see that there is a context in gctx, ctx is also there. So what am i doing wrong?

Forgot to add the error message i got;

The type of an object is inpatible with the expected type of the parameter associated to the object" code: "17 [Break On This Error] ctx.drawImage(gctx,corx,cory);

Thanks in advance also sorry in advance if it's a major newbie question,

I basically want to put a shape that the user "cuts" from the main canvas to a random place in the main canvas. I hold the cut out shape's context and want to use;

ctx.drawImage(gctx,corx,cory);

to put gctx, which holds the context of the cut shape in to ctx, which is the main canvas context. Both are global and already set when they e upon the above code line. Also gctx is set as below;

ghostcanvas = document.createElement('canvas');
ghostcanvas.height = canvas.height;
ghostcanvas.width = canvas.width;
gctx = ghostcanvas.getContext('2d');

From firebug i can see that there is a context in gctx, ctx is also there. So what am i doing wrong?

Forgot to add the error message i got;

The type of an object is inpatible with the expected type of the parameter associated to the object" code: "17 [Break On This Error] ctx.drawImage(gctx,corx,cory);

Thanks in advance also sorry in advance if it's a major newbie question,

Share Improve this question edited Apr 21, 2011 at 14:13 Mechanicum asked Apr 21, 2011 at 7:40 MechanicumMechanicum 411 silver badge3 bronze badges 1
  • Do you have an example set up for what you have? I think I may know what you need to do, but just not quite sure if I am on the right page with you. – jaredwilli Commented Jan 21, 2012 at 13:10
Add a ment  | 

1 Answer 1

Reset to default 5

You must pass the canvas as first parameter to drawImage. Not the context.

ctx.drawImage(ghostcanvas, corx, cory);

本文标签: javascriptCanvas context drawImage() problemStack Overflow