java调用摄像头进行拍照和保存
发布日期:2022-03-08 21:50:44
浏览次数:7
分类:技术文章
本文共 3263 字,大约阅读时间需要 10 分钟。
简单记录一下步骤,为了以后使用时方便。
1.创建一个springboot项目,pom依赖为``org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime org.projectlombok lombok true ** ** org.springframework.boot spring-boot-starter-test test com.github.sarxos webcam-capture 0.3.12 org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok
2.写一个测试类,代码为
package com.example.shexiangtou;import com.github.sarxos.webcam.Webcam;import com.github.sarxos.webcam.WebcamPanel;import com.github.sarxos.webcam.WebcamResolution;import com.github.sarxos.webcam.WebcamUtils;import com.github.sarxos.webcam.util.ImageUtils;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class TestWebCam { private static JFrame window; public static void main(String[] args) throws InterruptedException { Webcam webcam = Webcam.getDefault(); webcam.setViewSize(WebcamResolution.VGA.getSize()); WebcamPanel panel = new WebcamPanel(webcam); panel.setFPSDisplayed(true); panel.setDisplayDebugInfo(true); panel.setImageSizeDisplayed(true); panel.setMirrored(true); JFrame window = new JFrame("张世鹏的拍照小程序"); window.add(panel); window.setResizable(true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.setVisible(true); final JButton button = new JButton("点击进行拍照"); window.add(panel, BorderLayout.CENTER); window.add(button, BorderLayout.SOUTH); window.setResizable(true); window.pack(); window.setVisible(true); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { button.setEnabled(false); //设置按钮不可点击 //实现拍照保存-------start String fileName = "D://" + System.currentTimeMillis(); **//保存路径即图片名称(不用加后缀)** WebcamUtils.capture(webcam, fileName, ImageUtils.FORMAT_PNG); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JOptionPane.showMessageDialog(null, "拍照成功"); button.setEnabled(true); //设置按钮可点击 return; } }); //实现拍照保存-------end } }); }}
转载地址:https://blog.csdn.net/m0_55627541/article/details/121457440 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2024年03月15日 02时52分35秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
java 403怎么抛出_java – 如何在Spring MVC中返回403禁止?
2019-04-21
java jsch工具类_Java工具集-JSch连接远程服务器工具类
2019-04-21
php rand() 重复,php – mt_rand()给我总是相同的数字
2019-04-21
php taglib.php,thinkphp5 taglib自定义标签教程
2019-04-21
ctf常见php,CTF中常见的PHP伪协议
2019-04-21
php语言冒泡法,PHP 冒泡排序法
2019-04-21
php如何数组去重复,PHP如何去除数组重复元素?
2019-04-21
ui php h5,画出自己的UI组件的详情
2019-04-21
linux服务文件编写,linux编写systemd下服务脚本
2019-04-21
hdfs linux 目录是否存在,Linux中判断hdfs文件是否存在
2019-04-21
linux学习需要什么基础,学linux需要什么基础?
2019-04-21
高斯勒让德在c语言中的程序,c语言:用递归方法编写程序,求n阶勒让德多项式的值...
2019-04-21
c语言单片机电子时钟,新人求个51单片机的电子时钟汇编语言(C语言的还没学到)...
2019-04-21
c++语言文件流,C++文件流
2019-04-21
android 动态毛玻璃,Android毛玻璃背景效果简单实现代码
2019-04-21