html2canvas 可以捕获 javascript 3d 'screenshot' 吗?
Can html2canvas capture a javascript 3d 'screenshot'?
我看过一个 html2canvas 的例子,它创建了一个 html 块的 'screenshot'(例如:html2canvas example)。
我想做的是,使用 javascript,捕捉 three.js(或任何 js 3d 库)场景的 'screenshot'。
请记住,用户在决定 'screenshot' 之前可能会玩(旋转等)3d 场景。
可以 html2canvas 'capture' 3d 场景吗?
编辑
see plunker for code
see plunker for working solution
好吧,由于 three.js 绘制了一个 canvas,我敢肯定您可以在不使用 html2canvas.[=13 的情况下复制它的当前状态=]
function cloneCanvas(oldCanvas) {
//create a new canvas
var newCanvas = document.createElement('canvas');
var context = newCanvas.getContext('2d');
//set dimensions
newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height;
//apply the old canvas to the new one
context.drawImage(oldCanvas, 0, 0);
//return the new canvas
return newCanvas;
}
Thanks to Robert Hurst for his answer on the subject
关于 html2canvas,文档的这一段让我相信它能够复制画布,因为它没有被跨源内容污染。
Limitations
All the images that the script uses need to reside under the same origin for it to be able to read them without the assistance of a proxy. Similarly, if you have other canvas elements on the page, which have been tainted with cross-origin content, they will become dirty and no longer readable by html2canvas.
我看过一个 html2canvas 的例子,它创建了一个 html 块的 'screenshot'(例如:html2canvas example)。
我想做的是,使用 javascript,捕捉 three.js(或任何 js 3d 库)场景的 'screenshot'。
请记住,用户在决定 'screenshot' 之前可能会玩(旋转等)3d 场景。
可以 html2canvas 'capture' 3d 场景吗?
编辑
see plunker for code
see plunker for working solution
好吧,由于 three.js 绘制了一个 canvas,我敢肯定您可以在不使用 html2canvas.[=13 的情况下复制它的当前状态=]
function cloneCanvas(oldCanvas) {
//create a new canvas
var newCanvas = document.createElement('canvas');
var context = newCanvas.getContext('2d');
//set dimensions
newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height;
//apply the old canvas to the new one
context.drawImage(oldCanvas, 0, 0);
//return the new canvas
return newCanvas;
}
Thanks to Robert Hurst for his answer on the subject
关于 html2canvas,文档的这一段让我相信它能够复制画布,因为它没有被跨源内容污染。
Limitations
All the images that the script uses need to reside under the same origin for it to be able to read them without the assistance of a proxy. Similarly, if you have other canvas elements on the page, which have been tainted with cross-origin content, they will become dirty and no longer readable by html2canvas.