如何将渲染从three.js 转换为.png 文件? [英] How to convert render from three.js to .png file?
本文介绍了如何将渲染从three.js 转换为.png 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将渲染转换为 .png 图像?
How would I convert a render to a .png image?
我已经环顾了一段时间,但没有任何效果.
I've been looking around for awhile but nothing has worked.
推荐答案
这是我使用的一个函数和 a fiddle 表明它正在工作.
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();
}
这篇关于如何将渲染从three.js 转换为.png 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文