How to convert render from three.js to .png file?

烂漫一生 提交于 2019-12-30 06:57:21

问题


How would I convert a render to a .png image?

I've been looking around for awhile but nothing has worked.


回答1:


Here is a function I use and a fiddle that shows it working.

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


来源:https://stackoverflow.com/questions/40444995/how-to-convert-render-from-three-js-to-png-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!