Skip to content

Commit

Permalink
added snapshot button
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 26, 2023
1 parent 0493c9d commit 2267ef5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.util.Objects;

/**
* A panel that displays the default USB web camera.
*/
public class WebCamPanel extends JPanel {
private static final Logger logger = LoggerFactory.getLogger(WebCamPanel.class);
private final WebcamPanel panel;

public WebCamPanel() {
Expand All @@ -21,6 +30,27 @@ public WebCamPanel() {
panel = new WebcamPanel(webcam,false);
panel.setDrawMode(WebcamPanel.DrawMode.FIT); // fit, fill, or none
panel.setFPSDisplayed(true);

var toolBar = new JToolBar();
toolBar.setFloatable(false);

toolBar.add(new JButton(new AbstractAction() {
{
putValue(NAME, "Snapshot");
putValue(SHORT_DESCRIPTION, "Snapshot");
putValue(SMALL_ICON, new ImageIcon(Objects.requireNonNull(getClass().getResource("icons8-screenshot-16.png"))));
}
@Override
public void actionPerformed(ActionEvent e) {
BufferedImage img = panel.getWebcam().getImage();
if(img==null) return;
logger.info("Snapshot {}x{}",img.getWidth(),img.getHeight());
logger.error("Not implemented yet.");
}
}));


add(toolBar, BorderLayout.NORTH);
add(panel, BorderLayout.CENTER);
panel.start();
panel.pause();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2267ef5

Please sign in to comment.