ElementImage
ElementImage in UIToolbox saves what an element shows, such as a Graph or a PieChart, as an image. It reads the rendered frame at the end of the frame: the screen, or the targetTexture of the panel settings.
ElementImage.SavePng(graph, Path.Combine(Application.persistentDataPath, "graph.png"), ok => Debug.Log(ok ? "saved" : "failed"));
ElementImage.Capture(pie, texture => { /* use the texture, then Destroy it */ });
| Member | Description |
|---|---|
Capture(element, done) |
Copies the pixels of the element into a new RGBA32 texture, the right way up. The caller owns the texture. done gets null outside Play mode, off a runtime panel, or when the element does not show. |
Capture(panel, worldRect, done) |
The same for a rectangle of a panel, in world units. The ColorPicker eyedropper reads one pixel with it. |
SavePng(element, path, done) |
Captures the element and writes a PNG file. done gets false when there is no image or the file cannot be written (the error is logged). |
- The image is what shows on screen, so a window or popup on top of the element shows in the image too.
- World-space panels are not supported.
- A panel that renders to a texture needs a texture with a depth-stencil buffer, such as
new RenderTexture(w, h, 24). Without it, UI Toolkit draws the masked elements wrong: the rounded MDI windows show as white rectangles.