首页 > 解决方案 > Java net-beans - 如果用户登录失败,则使用网络摄像头捕获图像

问题描述

我想实现一个java应用程序,有一个登录表单,当用户登录失败时,使用默认网络摄像头捕获用户的图像并将其存储在一个文件夹中。

怎么可能开发呢?

我找到了一些与该主题相关的参考资料。

标签: java

解决方案


该项目的链接是https://github.com/sarxos/webcam-capture

更多参考 -在 java 中从网络摄像头捕获图像?

YouTube 教程:https ://www.youtube.com/watch?v=2BHyL_XK8YQ

示例代码(拍照并保存在test.jpg中):

import com.github.sarxos.webcam.Webcam;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;


   //Use try-catch block in the main method OR in any method & call that method in the main method
   try {
        // TODO add your handling code here:

        //infoBox("Hello", "Beta");
        Webcam webcam = Webcam.getDefault();
        webcam.open();
        BufferedImage image = webcam.getImage();
        ImageIO.write(image, "JPG", new File("test.jpg"));
    } catch (IOException ex) {
        Logger.getLogger(LoginPage.class.getName()).log(Level.SEVERE, null, ex);
    }

推荐阅读