org.openpnp.capture.OpenPnpCapture Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openpnp-capture-java Show documentation
Show all versions of openpnp-capture-java Show documentation
OpenPnP Capture Java with all binaries included, packaged for Maven.
package org.openpnp.capture;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import org.openpnp.capture.library.OpenpnpCaptureLibrary;
import com.sun.jna.Pointer;
public class OpenPnpCapture {
Pointer context;
public OpenPnpCapture() {
context = OpenpnpCaptureLibrary.INSTANCE.Cap_createContext();
}
public List getDevices() {
int deviceCount = OpenpnpCaptureLibrary.INSTANCE.Cap_getDeviceCount(context);
List devices = new ArrayList<>();
for (int deviceIndex = 0; deviceIndex < deviceCount; deviceIndex++) {
CaptureDevice device = new CaptureDevice(context, deviceIndex);
devices.add(device);
}
return devices;
}
public void close() {
OpenpnpCaptureLibrary.INSTANCE.Cap_releaseContext(context);
}
public Pointer getContext() {
return context;
}
public String getLibraryVersion() {
return OpenpnpCaptureLibrary.INSTANCE.Cap_getLibraryVersion().getString(0, "UTF8");
}
public static String getResultDescription(int result) {
switch (result) {
case OpenpnpCaptureLibrary.CAPRESULT_OK:
return "OK";
case OpenpnpCaptureLibrary.CAPRESULT_ERR:
return "Error";
case OpenpnpCaptureLibrary.CAPRESULT_DEVICENOTFOUND:
return "Device Not Found";
case OpenpnpCaptureLibrary.CAPRESULT_FORMATNOTSUPPORTED:
return "Format Not Supported";
case OpenpnpCaptureLibrary.CAPRESULT_PROPERTYNOTSUPPORTED:
return "Property Not Supported";
default:
return "" + result;
}
}
public static String fourCcToString(int fourCc) {
String s = "";
for (int i = 0; i < 4; i++) {
s += (char) (fourCc & 0xff);
fourCc >>= 8;
}
return s;
}
public static void main(String[] args) {
OpenPnpCapture capture = new OpenPnpCapture();
CaptureDevice device = capture.getDevices().get(0);
CaptureFormat format = device.getFormats().get(0);
CaptureStream stream = device.openStream(format);
BufferedImage image = stream.capture();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy