File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import io .github .doblon8 .openpnp .capture .LogLevel ;
33import io .github .doblon8 .openpnp .capture .OpenPnpCapture ;
44
5+ import javax .imageio .ImageIO ;
6+ import java .awt .*;
7+
58import static io .github .doblon8 .openpnp .capture .OpenPnpCapture .installCustomLogFunction ;
69import static io .github .doblon8 .openpnp .capture .OpenPnpCapture .setLogLevel ;
710
@@ -20,8 +23,17 @@ void main() {
2023
2124 try (var stream = device .openStream (format )) {
2225 System .out .println ("Stream is open: " + stream .isOpen ());
26+ TimeUnit .SECONDS .sleep (1 ); // wait a bit to get the webcam ready
27+
28+ var image = stream .capture ();
29+ ImageIO .write (image , "png" , new File ("/tmp/image.png" ));
30+ System .out .println ("Captured image saved to /tmp/image.png" );
31+ } catch (InterruptedException e ) {
32+ System .err .println ("Interrupted while waiting for webcam: " + e .getMessage ());
2333 }
2434 } catch (CaptureException e ) {
2535 System .err .println ("Error using CaptureContext: " + e .getMessage ());
36+ } catch (IOException e ) {
37+ System .err .println ("Error saving image: " + e .getMessage ());
2638 }
2739}
You can’t perform that action at this time.
0 commit comments