如何在没有标记的情况下获取 forgeviewer 的快照
How do I get a snapshot of the forgeviewer without markups
如何获取查看器的快照并将其单独保存为图像?
谢谢
这可以通过组合 Viewer3D#getScreenShot 方法和 Autodesk.Viewing.MarkupsCore
扩展的 renderToCanvas
方法来完成,如下所示:
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。
如何获取查看器的快照并将其单独保存为图像?
谢谢
这可以通过组合 Viewer3D#getScreenShot 方法和 Autodesk.Viewing.MarkupsCore
扩展的 renderToCanvas
方法来完成,如下所示:
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。