Sub SaveSnapshot
' Take a snapshot of the RootPane
Dim bmp As B4XBitmap = MainForm.RootPane.As(B4XView).Snapshot
' Open an output stream to save the image
Dim out As OutputStream
out = File.OpenOutput(File.DirApp, "screenshot.png", False)
' Save the snapshot as a PNG file
bmp.WriteToStream(out, 100, "PNG")
' Close the output stream
out.Close
Log("Screenshot saved as screenshot.png in the application directory.")
End Sub