简体   繁体   English

从Canvas Javascript获取图像

[英]Get Image from Canvas Javascript

I need to get an image from a canvas that is filled with a google map: 我需要从填充有Google地图的画布上获取图像:

  ...

  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  ...

  var canvas = document.getElementById("map-canvas");
  var ctx=canvas.getContext("2d");
  var url = canvas.toDataURL();

Doesn't work. 不起作用 It's broke up at the second line "var ctx=canvas.getContext("2d");" 它在第二行"var ctx=canvas.getContext("2d");" . Can anybody help me? 有谁能够帮助我? Is there a other way to have the same effect? 还有其他方法可以达到相同的效果吗?

You can't do this. 你做不到 Your element map-canvas isn't a canvas element ; 您的元素map-canvas不是canvas元素 it's just an element with an id 'map-canvas'. 它只是一个ID为'map-canvas'的元素。 Canvas methods only work on <canvas> elements. 画布方法仅适用于<canvas>元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM