将画布图像保存在指定位置,而不使用<a> element

时间:2017-08-22 05:50:52

标签: javascript html canvas

I want the canvas content to be saved as an image upon clicking a button. The button's OnClientClick() is attached to the following method. What it does is, it downloads the image and hence I needed an element of which the id is "link".

Can someone help me to get it saved to a location that I want ? I mean, I need to be able to specify the location for the file.

  <script type="text/javascript">
    function CanvasToImage() {
        var dataURL = can.toDataURL('image/png');
        document.location.href = dataURL.replace("image/png", "image/octet-stream");
        link.download = "test.png";
        link.href = canvas
            .toDataURL("image/png")
            .replace("image/png", "image/octet-stream");
        link.click();
    }
</script>

0 个答案:

没有答案