簡體   English   中英

將畫布作為圖像保存到ASP.net中的服務器

[英]Save a canvas as an image to the server in ASP.net

我有一個帶有谷歌地圖的頁面和一些div中的一些數據,我需要用戶點擊“Grab Screenshot”按鈕,這應該保存用戶頁面的屏幕截圖並將其保存到服務器。

我嘗試了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');
                }
            });
    }
    });
    }

我做了研究,我發現它是一些CORS問題,但我無法找到解決方案。

所以,我想知道我是否可以使用ASP.net做截圖,這可能嗎? 提前致謝。

我能夠使用代理成功地完成它。 我在地圖上的其他網站上遇到了自定義標記圖標的問題。 這導致帆布污染。 我將圖像移動到我的網站並更改了路徑,“污染的畫布可能無法導出”錯誤消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM