将画布保存为ASP.net中的服务器的图像

问题描述:

我有一个页面,其中包含Google地图以及一些div中的一些数据,我需要用户单击“抓取屏幕截图”按钮,并且应该保存用户页面的屏幕截图并将其保存到服务器。将画布保存为ASP.net中的服务器的图像

我通过Html2Canvas试过,但它没有让我的画布转换为dataurl即在我的JavaScript功能,我用这个:

function GenerateImage() 
    { 
    html2canvas($('#mainDiv'), { 
     onrendered: function(canvas) { 
      //this appends the canvas(screenshot) to the page, this is working fine 
       document.body.appendChild(canvas); 
      //this is not working, 
      //Error: SecurityError: The operation is insecure. 
      var image = canvas.toDataURL('image/png'); 
      image.crossOrigin = 'anonymous'; 
      var imgdata = image.replace(/^data:image\/(png|jpg);base64,/, ''); 

      $.ajax({ 
       url: '******', 
       data: { 
         imgdata:imgdata 
         }, 
       type: 'post', 
       success: function (response) { 
       console.log('Success'); 
       } 
      }); 
    } 
    }); 
    } 

我做了调查,我发现这是一些CORS问题,但我无法找出解决方案。

所以,我想知道如果我可以使用ASP.net做屏幕截图,那有可能吗?提前致谢。

+0

你可以试试: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toBlob –

+0

感谢您的答复,我试过一个太,我得到这个错误 - 未捕获SecurityError:未能在'HTMLCanvasElement'上执行'toBlob':受污染的画布可能无法导出 – lambda8

+0

我看到...您可以尝试http://*.com/questions/16235161/save-current-google-map-as-图片。也许你只是缺少useCORS:真 –

我能够使用代理成功地做到这一点。我在地图上的其他网站上遇到了自定义标记图标问题。这导致画布污染。我将图像移动到我的网站并改变了路径,“污染的画布可能无法导出”错误消失了。