Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将render从three.js转换为.png文件?_Three.js - Fatal编程技术网

如何将render从three.js转换为.png文件?

如何将render从three.js转换为.png文件?,three.js,Three.js,如何将渲染转换为.png图像 我已经四处寻找了一段时间,但什么都没用。这里是我使用的一个函数,它显示了它的工作原理 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('', '')

如何将渲染转换为.png图像


我已经四处寻找了一段时间,但什么都没用。

这里是我使用的一个函数,它显示了它的工作原理

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();
}
使用