Take a screenshot of a SceneView

Loading...

Note: Support for 3D on mobile devices may vary, view the system requirements for more information.

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.

view.takeScreenshot({
  format: 'jpg',
  quality: 70
});

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

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:

view.takeScreenshot({
  area: {
    x: 0,
    y: 0,
    width: 100,
    height: 100
  }
});

Sample search results

TitleSample
Loading...