How do I get a snapshot of the forgeviewer without markups

白昼怎懂夜的黑 提交于 2020-12-15 05:35:02

问题


How can i get a snapshot of the viewer and save it separately as an image?

Thank you


回答1:


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);
  });
}

Here's a codepen demonstrating the above code: https://codepen.io/petrbroz/pen/gOMPYRV?editors=0010.



来源:https://stackoverflow.com/questions/64352005/how-do-i-get-a-snapshot-of-the-forgeviewer-without-markups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!