UI Toolbox logoUI Toolbox
Support

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.

A trophy card, the ElementImage.SavePng call and the saved trophy.png as a second cardA trophy card, the ElementImage.SavePng call and the saved trophy.png as a second card

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.
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 ElementImageDemo scene shows a picture of a trophy card, saves with a picture of the place, a photo mode without the HUD and a result card saved as a PNG file.