Skip to content

Commit b22159e

Browse files
committed
Add usage example to README
1 parent fc3b14f commit b22159e

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,44 @@
22

33
Java Foreign Function & Memory bindings for [openpnp-capture](https://github.com/openpnp/openpnp-capture).
44

5+
## Example
6+
7+
```java
8+
import io.github.doblon8.openpnp.capture.*;
9+
10+
import javax.imageio.ImageIO;
11+
12+
import static io.github.doblon8.openpnp.capture.OpenPnpCapture.*;
13+
14+
void main() throws Exception {
15+
System.out.println("openpnp-capture version: " + OpenPnpCapture.getLibraryVersion());
16+
17+
setLogLevel(LogLevel.INFO);
18+
installCustomLogFunction((logLevel, message) -> System.out.println("Log [" + logLevel + "]: " + message));
19+
20+
try (var capture = new OpenPnpCapture()) {
21+
var device = capture.getDevices().stream()
22+
.findFirst()
23+
.orElseThrow(() -> new CaptureException("No capture devices found."));
24+
25+
var format = device.getFormats().stream()
26+
.findFirst()
27+
.orElseThrow(() -> new CaptureException("No formats found."));
28+
29+
try (var stream = device.openStream(format)) {
30+
TimeUnit.SECONDS.sleep(1); // let the camera initialize
31+
32+
var zoomLimits = stream.getPropertyLimits(CaptureProperty.ZOOM);
33+
System.out.println("Zoom limits: " + zoomLimits);
34+
35+
var image = stream.capture();
36+
ImageIO.write(image, "png", new File("/tmp/image.png"));
37+
System.out.println("Captured image saved to /tmp/image.png");
38+
}
39+
}
40+
}
41+
```
42+
543
## License
644

745
This project is licensed under the MIT License, the same as the `openpnp-capture` library.

0 commit comments

Comments
 (0)