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