如何将渲染从three.js转换为.png文件?
答
这是我使用的功能和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();
}
用['canvas.toDataURL( “图像/ PNG”);'](http://stackoverflow.com/questions/923885/capture-html-canvas-as-gif-jpg-png-pdf ) –