@Override
public BufferedImage getImage() {
if (!open) {
throw new RuntimeException("Webcam has to be open to get image");
}
Buffer buffer = grabber.grabFrame();
Image image = converter.createImage(buffer);
if (image == null) {
throw new RuntimeException("Cannot get image");
}
int width = image.getWidth(null);
int height = image.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB;
BufferedImage buffered = new BufferedImage(width, height, type);
Graphics2D g2 = buffered.createGraphics();
g2.drawImage(image, null, null);
g2.dispose();
buffered.flush();
return buffered;
}