Java Program to Take a Snapshot From System Camera

It is better to have a brief knowledge of the Swing class of java as it is applied in the implementation to do so as whenever there arises a need to deal with images or dealing with the two-dimensional matrix as an output or usage of it in generating the output in java, Swing class comes into play in achieving the same.

CODE

 

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Snapshot {

public static void main(String[] args) throws IOException {
// Get the default webcam.
Webcam webcam = Webcam.getDefault();

// Capture an image.
BufferedImage image = webcam.getImage();

// Save the image to a file.
ImageIO.write(image, “jpg”, new File(“snapshot.jpg”));

// Close the webcam.
webcam.close();
}
}

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top