Take a screenshot of a SceneView

This sample shows how to use the SceneView.takeScreenshot() method to create an image of the current view. The method returns a promise that resolves with a Screenshot object that contains the raw ImageData and the image as a data url. In this sample we add the image data to a canvas so that we can add a custom text on top of it.

Several options can be passed into the method.

The image format can be jpg or png. If the format is jpg you can also set the quality parameter.

Use dark colors for code blocksCopy
1
2
3
4
view.takeScreenshot({
  format: "jpg",
  quality: 70
});

The image can be scaled up or down, by setting the width or the height of the image:

Use dark colors for code blocksCopy
1
2
3
4
5
view.takeScreenshot({
  // scale down image to 50%
  // height is calculated from aspect ratio of the view
  width: view.width / 2
});

Sometimes it is useful to create an image of an area of the view. In this case we can use the area parameter to only take a screenshot of a section of the screen:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
view.takeScreenshot({
  area: {
    x: 0,
    y: 0,
    width: 100,
    height: 100
  }
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.