[英]Save a canvas as an image to the server in ASP.net
I have a page with a google map in it and some data in a couple of divs, I need the user to click "Grab Screenshot" button and that should save the screenshot of the user's page and save it to the server. 我有一个带有谷歌地图的页面和一些div中的一些数据,我需要用户点击“Grab Screenshot”按钮,这应该保存用户页面的屏幕截图并将其保存到服务器。
I tried through Html2Canvas, but it is not allowing me to convert canvas to dataurl ie in my javascript function, I used this: 我尝试了Html2Canvas,但它不允许我将canvas转换为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');
}
});
}
});
}
I did research, I found out it is some CORS issue, but I am unable to figure out a solution. 我做了研究,我发现它是一些CORS问题,但我无法找到解决方案。
So, I was wondering if I can do a screenshot using ASP.net, is that possible? 所以,我想知道我是否可以使用ASP.net做截图,这可能吗? Thanks in advance.
提前致谢。
I was able to successfully do it using the proxy. 我能够使用代理成功地完成它。 I had an issue with a custom marker icon from a different website on the map.
我在地图上的其他网站上遇到了自定义标记图标的问题。 That was causing the canvas to taint.
这导致帆布污染。 I moved the image to my website and changed the path, the "tainted canvases may not be exported" error went away.
我将图像移动到我的网站并更改了路径,“污染的画布可能无法导出”错误消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.