How do you save an image from a Three.js canvas?

后端 未结 3 1625

How do you save an image from a Three.js canvas?

I\'m attempting to use Canvas2Image but it doesn\'t like to play with Threejs. Since the canvas isn\'t defined until

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 03:35

    use canvas to create the url, and then the same can be downloaded

    function createImage(saveAsFileName) {
    
        var canvas = document.getElementById("canvas");
    
        var url = canvas.toDataURL();
    
        var link = document.createElement('a');
    
        link.setAttribute('href', url);
        link.setAttribute('target', '_blank');
        link.setAttribute('download', saveAsFileName);
    
        link.click();
    }
    

提交回复
热议问题