1

I am trying to copy the image from one canvas to another canvas. I have seen an answer saying that an easy way to do it is:

var Scanvas = $("#sourceCanvas");

var Scontext = Scanvas.get(0).getContext("2d");

var Dcanvas = $("#destinationCanvas");

var Dcontext = Scanvas.get(0).getContext("2d");

//draw something in Scanvas

Dcontext.drawImage(Scanvas, 0 ,0);

However, whenever I try this I keep getting a Type Error. The browser I am using is an up-to-date version of Google Chrome, so I don't think that is the problem.

Poonam
  • 4,591
  • 1
  • 15
  • 20

1 Answers1

0

You are using a jQuery object as the first parameter of drawImage().

It needs to be a pure DOM object.

You can access the underlying DOM objects in jQuery by calling get() and specifically get(0) if there is only one object in jQuery selection, as mentioned in the comments.

   DContext.drawImage(Scanvas.get(0),....)
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435