0

I am drawing an image onto canvas. after that I do canvas.toDataUrl("image/png"); But it doesn't go fine. Here is the link to jsfiddle!

http://jsfiddle.net/QcS4u/34/

MJQ
  • 1,778
  • 6
  • 34
  • 60

1 Answers1

1

You cannot use toDataUrl after loading an image from another domain into the canvas, as it would open up a security hole (information disclosure from other domains).

See why is this toDataURL line a security error?.

Community
  • 1
  • 1
nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • @MJQ You also can't draw the image to canvas before it has loaded/been cached. – Paul S. Aug 28 '12 at 13:03
  • Well, no, the image draw actually does work. It's the `toDataUrl` that doesn't, exactly as @MJQ said. – nneonneo Aug 28 '12 at 13:05
  • No, in that case you are using `toDataUrl` before the image is drawn. So `toDataUrl` works but produces a blank canvas image. – nneonneo Aug 28 '12 at 13:16
  • No! I first draw image then do toDataUrl and then again draw image from src of toDataUrl!!!!! – MJQ Aug 28 '12 at 13:20
  • Now that I have added image to the document, but it is still not getting it in toDataUrl!!!!!! – MJQ Aug 28 '12 at 13:26
  • As I pointed out in my answer, you **cannot** use `toDataUrl` after loading a foreign image into a canvas. You just can't. If you have more questions, open a new question. – nneonneo Aug 28 '12 at 14:00