如何在没有标记的情况下获取 forgeviewer 的快照 [英] How do I get a snapshot of the forgeviewer without markups
本文介绍了如何在没有标记的情况下获取 forgeviewer 的快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取查看器的快照并将其单独保存为图像?
How can i get a snapshot of the viewer and save it separately as an image?
谢谢
推荐答案
这可以通过结合 Viewer3D#getScreenShot 方法和 Autodesk.Viewing.MarkupsCore
的 renderToCanvas
方法代码> 扩展,像这样:
This can be done by combining the Viewer3D#getScreenShot method and the renderToCanvas
method of the Autodesk.Viewing.MarkupsCore
extension, like so:
async function getScreenshotDataUrl(viewer, width, height) {
const markupExt = await viewer.getExtension('Autodesk.Viewing.MarkupsCore');
return new Promise(function (resolve, reject) {
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const context = canvas.getContext('2d');
const image = new Image();
image.onload = function () {
context.drawImage(image, 0, 0);
markupExt.renderToCanvas(context, function () {
resolve(canvas.toDataURL('image/png'));
});
};
viewer.getScreenShot(width, height, blob => image.src = blob);
});
}
这是一个演示上述代码的代码笔:https://codepen.io/petrbroz/pen/gOMPYRV?editors=0010.
Here's a codepen demonstrating the above code: https://codepen.io/petrbroz/pen/gOMPYRV?editors=0010.
这篇关于如何在没有标记的情况下获取 forgeviewer 的快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文