capturePng
Captures one frame and return the png data for that frame.
Captures the physical pixels in rect, or if null the entire OS window.
The returned data is allocated by Self.allocator and should be freed by the caller.
Parameters
- frame:dvui.App.frameFunction
- dvui.App.frameFunction
- rect:?dvui.Rect.Physical
- ?dvui.Rect.Physical
- writer:*std.Io.Writer
- *std.Io.Writer
Source
Implementation
pub fn capturePng(frame: dvui.App.frameFunction, rect: ?dvui.Rect.Physical, writer: *std.Io.Writer) !void {
var picture = dvui.Picture.start(rect orelse dvui.windowRectPixels()) orelse {
std.debug.print("Current backend does not support capturing images\n", .{});
return error.Unsupported;
};
// run the gui code
if (try frame() == .close) return error.closed;
// render the retained dialogs and deferred renders
_ = dvui.currentWindow().endRendering(.{});
picture.stop();
// texture will be destroyed in picture.deinit() so grab pixels now
try picture.png(writer);
// draw texture and destroy
picture.deinit();
const cw = dvui.currentWindow();
_ = try cw.end(.{});
try cw.begin(cw.frame_time_ns + 100 * std.time.ns_per_ms);
}