Take a screenshot of a SceneView

Explore in the sandboxView live

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.

  format: "jpg",
  quality: 70

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

  // 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:

  area: {
    x: 0,
    y: 0,
    width: 100,
    height: 100