export cesium image to png or jpg - screenshot

I need to generate an image to my app with images of cesium and objects (lines, polygons and points), but looking at the Forums new found no function like. I’ve tried viewer.canvas.toDataUrl but appears only a black image.

How do I take a screenshot of cesium? Or how do I export an image of type png or jpeg of a desired area?

You need to call viewer.render() immediately before toDataUrl in order to guarantee their is a scene on the canvas.

viewer.render();

viewer.canvas.toDataUrl();

thank

it’s worked !!!