Camera:snapshot(file)method

Captures the most recently received camera frame and saves it to the specified file.
The output format is determined by the file extension. Supported formats are .png, .jpg / .jpeg, and .bmp.

Notes

  • Returns false if no frame has been received yet or if the file cannot be written.
  • The Camera constructor already waits for the first frame, so a snapshot taken immediately after construction will succeed.

Parameters

file

The destination file path as a string or a File. The file extension determines the image format (.png, .jpg, .bmp).

Return value

Returns true if the snapshot was saved successfully, or false if an error occurred.

Example

--! luart-extensions import capture local cam = capture.Camera() if cam:snapshot("photo.png") then print("Snapshot saved to photo.png") else print("Failed to save snapshot") end