2016-11-06 42 views
2

如何将渲染转换为.png图像?如何将渲染从three.js转换为.png文件?

我一直在寻找一段时间,但没有任何工作。

+1

用['canvas.toDataURL( “图像/ PNG”);'](http://stackoverflow.com/questions/923885/capture-html-canvas-as-gif-jpg-png-pdf ) –

回答

1

这是我使用的功能和a fiddle,它显示它的工作。

function takeScreenshot() { 
    // For screenshots to work with WebGL renderer, preserveDrawingBuffer should be set to true. 
    // open in new window like this 
    var w = window.open('', ''); 
    w.document.title = "Screenshot"; 
    //w.document.body.style.backgroundColor = "red"; 
    var img = new Image(); 
    img.src = renderer.domElement.toDataURL(); 
    w.document.body.appendChild(img); 

    // download file like this. 
    //var a = document.createElement('a'); 
    //a.href = renderer.domElement.toDataURL().replace("image/png", "image/octet-stream"); 
    //a.download = 'canvas.png' 
    //a.click(); 
}